ipsec600
asked on
(401) Unauthorized
Hi experts,
I am following the below link and trying to post to my twitter account but receiving the below error, can you please advise what I am missing.
http://www.markhagan.me/Samples/Grant-Access-And-Tweet-As-Twitter-User-ASPNet
Error that I am receiving:
Server Error in '/' Application.
The remote server returned an error: (401) Unauthorized.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.WebException: The remote server returned an error: (401) Unauthorized.
Source Error:
Line 34: string pin = Request["oauth_verifier"]. ToString() ;
Line 35:
Line 36: var tokens = OAuthUtility.GetAccessToke n(
Line 37: oauth_consumer_key,
Line 38: oauth_consumer_secret,
Source File: c:\Twitter\page4.aspx.cs Line: 36
Stack Trace:
[WebException: The remote server returned an error: (401) Unauthorized.]
System.Net.HttpWebRequest. GetRespons e() +6592536
Twitterizer.WebRequestBuil der.Execut eRequest() +64
Twitterizer.OAuthUtility.G etAccessTo ken(String consumerKey, String consumerSecret, String requestToken, String verifier, WebProxy proxy) +550
[TwitterizerException: The remote server returned an error: (401) Unauthorized.]
Twitterizer.OAuthUtility.G etAccessTo ken(String consumerKey, String consumerSecret, String requestToken, String verifier, WebProxy proxy) +706
Twitterizer.OAuthUtility.G etAccessTo ken(String consumerKey, String consumerSecret, String requestToken, String verifier) +50
L1Twitter.Challenge4.btnDo ne_Click(O bject sender, EventArgs e) in c:\Twitter\page4.aspx.cs:3 6
System.Web.UI.WebControls. Button.OnC lick(Event Args e) +9750842
System.Web.UI.WebControls. Button.Rai sePostBack Event(Stri ng eventArgument) +196
System.Web.UI.WebControls. Button.Sys tem.Web.UI .IPostBack EventHandl er.RaisePo stBackEven t(String eventArgument) +10
System.Web.UI.Page.RaisePo stBackEven t(IPostBac kEventHand ler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePo stBackEven t(NameValu eCollectio n postData) +35
System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt) +1724
I am following the below link and trying to post to my twitter account but receiving the below error, can you please advise what I am missing.
http://www.markhagan.me/Samples/Grant-Access-And-Tweet-As-Twitter-User-ASPNet
Error that I am receiving:
Server Error in '/' Application.
The remote server returned an error: (401) Unauthorized.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.WebException: The remote server returned an error: (401) Unauthorized.
Source Error:
Line 34: string pin = Request["oauth_verifier"].
Line 35:
Line 36: var tokens = OAuthUtility.GetAccessToke
Line 37: oauth_consumer_key,
Line 38: oauth_consumer_secret,
Source File: c:\Twitter\page4.aspx.cs Line: 36
Stack Trace:
[WebException: The remote server returned an error: (401) Unauthorized.]
System.Net.HttpWebRequest.
Twitterizer.WebRequestBuil
Twitterizer.OAuthUtility.G
[TwitterizerException: The remote server returned an error: (401) Unauthorized.]
Twitterizer.OAuthUtility.G
Twitterizer.OAuthUtility.G
L1Twitter.Challenge4.btnDo
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.Page.RaisePo
System.Web.UI.Page.RaisePo
System.Web.UI.Page.Process
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Twitterizer;
namespace Twitter
{
public partial class page4 : System.Web.UI.Page
{
protected void Click(object sender, EventArgs e)
{
var oauth_consumer_key = "4K0zIxoVlQb4ach4gAZT";
var oauth_consumer_secret = "tQgZARLhyLjT20EdkpRt30nn0q5skQiT9qINAMU0x";
if (Request["Oauth_token"] == null)
{
OAuthTokenResponse reqToken = OAuthUtility.GetRequestToken(
oauth_consumer_key,
oauth_consumer_secret,
Request.Url.AbsoluteUri);
Response.Redirect(string.Format("http://twitter.com/oauth/authorize?oauth_token={0}",
reqToken.Token));
}
else
{
string requestToken = Request["oauth_token"].ToString();
string pin = Request["oauth_verifier"].ToString();
var tokens = OAuthUtility.GetAccessToken(
oauth_consumer_key,
oauth_consumer_secret,
requestToken,
pin);
OAuthTokens accesstoken = new OAuthTokens()
{
AccessToken = tokens.Token,
AccessTokenSecret = tokens.TokenSecret,
ConsumerKey = oauth_consumer_key,
ConsumerSecret = oauth_consumer_secret
};
TwitterResponse<TwitterStatus> response = TwitterStatus.Update(
accesstoken,
"Testing!! It works");
if (response.Result == RequestResult.Success)
{
Response.Write("we did it!");
}
else
{
Response.Write("Its all Working");
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so much Gary for your support.
ASKER