Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "Could not authenticate with OAuth." from Twitter when trying to POST

I'm successfully able to get an access token through the OAuth process.

However, when I try to run a POST to the /statuses/update.json endpoint, I get a "Could not authenticate with OAuth."

I'm signing with the token I got back from authenticating with my consumer secret, I don't understand what else could be.

Twitter forums were no help either.

Any tips would be greatly appreciated.

like image 914
john Avatar asked Jul 29 '11 06:07

john


1 Answers

Making authenticated calls to Twitter can be a pain.

Make sure that the parameters in your signature base string are ordered alphabetically.

Take this:

oauth_consumer_key={consumerkey}&oauth_nonce={nonce}&oauth_signature_method=HMAC-SHA1&oauth_timestamp={timestamp}&oauth_token={token}&oauth_version=1.0&status={tweet text}

fill out the values, encode it in Base64, and then put it together like this:

POST&{base64 encoded url}&{base64 encoded base string}

this will be the string you need to sign (without the brackets). (The url in this case will be https://api.twitter.com/1.1/statuses/update.json)

The signing key needs to be built like this:

{consumer secret}&{token secret}

The signature is a HMACSHA1 hash, which is then base64 encoded.

Then you need to put this in the Authorization header:

OAuth oauth_consumer_key="{consumer key}",oauth_nonce="{nonce}",oauth_signature="{signature}",oauth_signature_method="HMAC-SHA1",oauth_timestamp="{timestamp}",oauth_token="{token}",oauth_version="1.0"

And finally put status=your tweet text as the posted data in your request.

I hope this helps.

like image 52
parachutingturtle Avatar answered Nov 08 '22 14:11

parachutingturtle