Search code examples
twitteroauthtweetinvi

(401) Unauthorized calling https://api.twitter.com/oauth/access_token using tweetinvi


I started playing with tweetinvi to connect to twitter api. I keep getting "The remote server returned an error: (401) Unauthorized." error message when I call CredentialsCreator.GetCredentialsFromVerifierCode() after being redirected.

  1. I added my phone to my account.
  2. I made use the Consumer Key and Consumer Secret are the same.
  3. I made use that my time is current
  4. The callback url in app settings is http://127.zero.zero.1:53260/

I'm kinda of lost on what to do next.

Imgur

This is the only code that I use:

    protected void Page_Load( object sender, EventArgs e )
    {
        Tweetinvi.WebLogic.TemporaryCredentials applicationCredentials = (Tweetinvi.WebLogic.TemporaryCredentials)CredentialsCreator.GenerateApplicationCredentials( Properties.Settings.Default.TwitterConsumerKey, Properties.Settings.Default.TwitterConsumerSecret );

        if (Request["oauth_token"] == null)
        {

            string url = CredentialsCreator.GetAuthorizationURLForCallback( applicationCredentials, "http://127.0.0.1:53260/twitter.aspx" );

            Response.Redirect( url, false );

        }
        else
        {
            string verifierCode = Request["oauth_verifier"];

                        // error calling this code
            var newCredentials = CredentialsCreator.GetCredentialsFromVerifierCode( verifierCode, applicationCredentials );

            Console.WriteLine( "Access Token = {0}", newCredentials.AccessToken );
            Console.WriteLine( "Access Token Secret = {0}", newCredentials.AccessTokenSecret );

        }
    }

Solution

  • Looks like you have everything correct. It might be the library you are using. Have you tried LinqToTwitter?

    They have several examples you can test at http://linqtotwitter.codeplex.com/SourceControl/latest#ReadMe.txt. Just download their source files and you'll find Linq2TwitterDemos_WebForms project that you can text out.