Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 639
  • Last Modified:

(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.GetAccessToken(
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.GetResponse() +6592536
   Twitterizer.WebRequestBuilder.ExecuteRequest() +64
   Twitterizer.OAuthUtility.GetAccessToken(String consumerKey, String consumerSecret, String requestToken, String verifier, WebProxy proxy) +550

[TwitterizerException: The remote server returned an error: (401) Unauthorized.]
   Twitterizer.OAuthUtility.GetAccessToken(String consumerKey, String consumerSecret, String requestToken, String verifier, WebProxy proxy) +706
   Twitterizer.OAuthUtility.GetAccessToken(String consumerKey, String consumerSecret, String requestToken, String verifier) +50
   L1Twitter.Challenge4.btnDone_Click(Object sender, EventArgs e) in c:\Twitter\page4.aspx.cs:36
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9750842
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +196
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

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");
                }
            }
        }
    }

Open in new window

0
ipsec600
Asked:
ipsec600
  • 2
  • 2
2 Solutions
 
GaryCommented:
The code it is based on is defunct and will never work anymore
0
 
ipsec600Author Commented:
Thank you so much Gary, could you please advise me any available link that I can follow.
0
 
GaryCommented:
This one is still current
http://linqtotwitter.codeplex.com/

Else there is a few more here
https://dev.twitter.com/docs/twitter-libraries
0
 
ipsec600Author Commented:
Thank you so much Gary for your support.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now