(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

ipsec600Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
The code it is based on is defunct and will never work anymore
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Twitter

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.