Monday, July 30, 2018

215 error while requesting Token from Twitter oAuth API

Leave a Comment

I'm trying to Implement Twitter login in my NodeJS app.

As per the documentation from Twitter, I need to pass the below parameters to this url via POST request. URL:

https://api.twitter.com/oauth/request_token

PARAMETERS:

 oauth_nonce=,   oauth_signature=,   oauth_callback="http%3A%2F%2Fmyapp.com%3A3005%2Ftwitter%2Fprocess_callback",   oauth_signature_method="HMAC-SHA1",         oauth_timestamp="currentTimestamp",   oauth_consumer_key=“myKEY”,   oauth_version="1.0" 

I'm passing a random string for oauth_nonce parameter. I'm not clear on how to create a oauth_signature?

I keep getting 215 error whenever I make the POST request beacuse of incorrect oauth_nonce and oauth_signature values I guess.

How do I generate oauth_nonce and oauth_signature values while making the request in NodeJS.

3 Answers

Answers 1

Those parameters need to be passed in your authorization header:

OAuth oauth_nonce="K7ny27JTpKVsTgdyLdDfmQQWVLERj2zAK5BslRsqyw",  oauth_callback="http%3A%2F%2Fmyapp.com%3A3005%2Ftwitter%2Fprocess_callback",  oauth_signature_method="HMAC-SHA1",  oauth_timestamp="1300228849",  oauth_consumer_key="OqEqJeafRSF11jBMStrZz",  oauth_signature="Pc%2BMLdv028fxCErFyi8KXFM%2BddU%3D",  oauth_version="1.0" 

But before that, you need to get a signature, which will then give you all of the parameters above. Check the documentation here.

A recommendation would be to use a 3rd party library like passport, which heavily simplifies this process if needed.

Answers 2

Twitter makes a whole lot of sense if used correctly. I have seen some tutorials that has been quite useful to those around me, that I feel maybe you might want to check Node Authentication: Twitter and Implementing Sign in with Twitter for Node.js

If you're using reactjs, this (npm i react-twitter-auth) might be useful to you too

Answers 3

can't comment, that's why answering here. the docu sais, oauth_nonce:

is a unique token your application should generate for each unique request

it is like the salt of the encryption. you can find oauth_signature under the same link. how to generate it is described here.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment