Prash's Blog

oauth.signpost.exception.OAuthNotAuthorizedException: Authorization failed (server replied with a 401). This can happen if the consumer key was not correct or the signatures did not match January 6, 2012

Filed under: Android — prazjain @ 1:00 pm
Tags: , , ,

I got this error when trying to post a simple tweet from my android app into twitter.

I had a sample test app created in twitter that I was using for a couple of days and it worked fine with all its consumer keys / secrets. But just before I was about to release the android app and created a new twitter app for use in release BOOM! I get this error! All I did was replace the CONSUMER KEY  and CONSUMER SECRET.

I searched the net all over the place but nothing could solve my issue.

Here is the resolution that worked.

In Twitter you can create apps that are either Browser based or Client based. Earlier twitter had a mechanism where it will ask the user to choose their app type. As seen in the below screenshot.

Here user can easily specify whatever type of application he intends to make. Also the callback url is optional because your android app application will overwrite it anyways to receive a callback.

Previous version of Twitter's Application creation page

Previous version of Twitter's Application creation page

Previous version of Twitter’s Application creation page

The new Twitter application creation page looks like this :

New Version of Twitter's application creation page

New Version of Twitter's application creation page

Here still the callback url is optional but what is not mentioned here in description is, this field is also used to determine if your application is a Client or Browser based application.

So only if you fill callback url for your application, it will be considered as browser based application else it will be considered as a client application.

In my case in the first test app I had set callback url but when I created a second app on twitter I left it out (because it is an optional field) and hence the Authorization failed.

So remember to give your application Read and Write Access and assign it a callback url so twitter will know that it is a browser based application.

I hope that helps.

Advertisements
 

11 Responses to “oauth.signpost.exception.OAuthNotAuthorizedException: Authorization failed (server replied with a 401). This can happen if the consumer key was not correct or the signatures did not match”

  1. anirvan Says:

    i can only imagine how you cracked this, but you certainly made my day!

  2. Please verify if the TIME and DATE on the device are up to date. That might cause problems with the Access Tokens

    • prazjain Says:

      Indeed sometimes if that is the cause the issue can be resolved like that.

      • vikram Says:

        I have check time and date both in device but it’s not working. And I have added callback url http://example.com/ in my app and make it read and write but still it’s not working. What are the other causes for this.

      • prazjain Says:

        I see that you have set the callback url in your app programmatically. But have you set callback url in the twitter app creation page? Try setting it there.

  3. Adhir Says:

    i have the same problem though i have set callback url and time of my emulator but still above solution is not working , can anyone provide me some help .

  4. Manivel Says:

    Anyone please help me .

    i have same problem . i set to read & write and also set date and Time issues.

    Still i can’t able to integarate Twitter in my android applciation.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s