215 error while requesting Token from Twitter oAuth API
Asked Answered
K

4

6

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.

Kaylor answered 19/7, 2018 at 7:47 Comment(1)
no progress up till now?Eng
B
5

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.

Bandolier answered 24/7, 2018 at 16:52 Comment(1)
Sure, here is a link to the respective documentationBandolier
E
1

To answer your question:

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

Going through these post will be of help to you Creating a signature and How to generate an OAuth nonce.

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

Or you might want to check passportjs

You will have to install it in your project by running: npm install passport-twitter

Configuration

const passport = require('passport')
  , TwitterStrategy = require('passport-twitter').Strategy;

passport.use(new TwitterStrategy({
    consumerKey: TWITTER_CONSUMER_KEY,
    consumerSecret: TWITTER_CONSUMER_SECRET,
    callbackURL: "http://www.example.com/auth/twitter/callback"
  },
  function(token, tokenSecret, profile, done) {
    User.findOrCreate(..., function(err, user) {
      if (err) { return done(err); }
      done(null, user);
    });
  }
));

This Github repo might be a great reference to you.

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

Eng answered 30/7, 2018 at 7:0 Comment(0)
S
0

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.

Synchrotron answered 24/7, 2018 at 7:7 Comment(0)
K
0

Finally I could get Access Token using this library

Kaylor answered 1/8, 2018 at 9:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.