Getting "Failed to authenticate using OAuth." from Twitter while trying to post

I can successfully get the access token through the OAuth process.

However, when I try to run POST on the endpoint /statuses/update.json, I get the message “Authentication failed with OAuth”.

I sign up with the token that I received from authentication with my consumer secret, I do not understand what else could be.

Twitter forums didn't help either.

Any advice is appreciated.

+6
source share
1 answer

Making authenticated calls on Twitter can be a pain.

Ensure that the parameters in the signature baseline are alphabetically ordered.

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 in the values, encode them in Base64 and then connect them as follows:

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

it will be the string to be signed (without brackets). (In this case, the URL will be https://api.twitter.com/1.1/statuses/update.json )

The signing key should be constructed as follows:

 {consumer secret}&{token secret} 

The signature is an HMACSHA1 hash, which is then encoded by base64.

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" 

Finally, put status=your tweet text as the published data in your request.

Hope this helps.

0
source

Source: https://habr.com/ru/post/893843/


All Articles