Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get request_token using OAuth with twitter

Tags:

oauth

twitter

I am using the following method URI to request token from twitter.

Note: here new lines are just for display purpose only.

http://twitter.com/oauth/request_token?
oauth_consumer_key=9cS99b2406CUpATOeggeA&
oauth_signature_method=HMAC-SHA1&
oauth_signature=3e18bafc4c4fd6b23f988bcd1a8c0ab2d65db784
oauth_timestamp=1267523137&
oauth_nonce=56e66e9f8bd28b320f86a16407f9911d&
oauth_version=1.0&
oauth_callback=http://playground.com

But it gives error "Failed to validate oauth signature and token".

The base string I used to computer signature is as bellow:

GET&
http%3A%2F%2Ftwitter.com%2Foauth%2Frequest_token&
oauth_consumer_key%3D9cS99b2406CUpATOeggeA%26
oauth_signature_method%3DHMAC-SHA1%26
oauth_timestamp%3D1267523137%26
oauth_nonce%3D56e66e9f8bd28b320f86a16407f9911d%26
oauth_version%3D1.0%26
oauth_callback%3Dhttp%3A%2F%2Fplayground.com


Please correct me where am I making mistake.

like image 887
Amit Avatar asked Mar 02 '10 10:03

Amit


People also ask

How can I get OAuth token from Twitter?

Generating access tokensLogin to your Twitter account on developer.twitter.com. Navigate to the Twitter app dashboard and open the Twitter app for which you would like to generate access tokens. Navigate to the "Keys and Tokens" page. Select 'Create' under the "Access token & access token secret" section.


1 Answers

Your problem is with the order of the parameters. The parameters for the base string need to be in order. If they are out of order, it will give you that error.

So your base string should be this...

GET&
http%3A%2F%2Ftwitter.com%2Foauth%2Frequest_token&
oauth_consumer_key%3D9cS99b2406CUpATOeggeA%26
oauth_nonce%3D56e66e9f8bd28b320f86a16407f9911d%26
oauth_signature_method%3DHMAC-SHA1%26
oauth_timestamp%3D1267523137%26
oauth_version%3D1.0%26
oauth_callback%3Dhttp%3A%2F%2Fplayground.com

Notice that your "nonce" was not in the correct spot.

Also, normally, the "signature" parameter is appended to the end of the request URL.

http://oauth.net/core/1.0a/#anchor46

Appendix A.5.1

like image 186
Ryan Alford Avatar answered Sep 25 '22 01:09

Ryan Alford