Twitter oAuth authorization failed 401 when using callback api

Recently I was trying to connect to twitter for a project and the first step was to authenticate using oAuth.
Twitter uses the oAuth 1.0a specification and one way to authenticate is for twitter to call a specific callback with the user’s token.
You can specify which callback url twitter will call when complete, which I had done, but every time I tried to authenticate, it threw this error:

Authorization failed (server replied with a 401).
This can happen if the consumer key was not correct or the signatures did not match.

I checked the consumer key and the signatures and they were ok.
As it turns out, if you want to use the callback mechanism, you have to specify a callback url in the twitter application settings.
To do this go to https://dev.twitter.com and sign in. Under your username click My Applications.
Select the application you’re using and select the Settings tab.
Then enter any callback you want into the callback url setting.

This is a weird quirk, but it was mentioned in the twitter developer forum.
After setting the callback url to something, in my case to http://blog.arextech.net/callback I was able to use the previous calls which didn’t work, unchanged, and they worked.
Source:
Twitter developer discussion

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">