Open skeddles opened 6 years ago
TLDR I think this won't work; you need to use some other library (such as request) to get the request_token. More detail:
The first problem is that node-twitter prepends an API version string to the request path, which isn't wanted for the oauth URLs. So your code as written requests this:
https://api.twitter.com/1.1/oauth/request_token
...but you want this:
https://api.twitter.com/oauth/request_token
You can work around the issue by passing a full URL for the first argument to client.post(), which will override the built-in base URLs.
However, your next problem is that, contrary to the documentation, the request_token endpoint's response format isn't actually JSON, it's url-encoded form data. node-twitter assumes response bodies are always JSON and it crashes with a parse error.
I had to use request.js to get this working. Here's sample code:
const request = require('request');
const options = {
headers: {
Accept: '*/*',
Connection: 'close',
'User-Agent': 'node-twitter/1'
},
oauth: {
consumer_key: MYKEY,
consumer_secret: MYSECRET,
token: MYAPPTOKEN,
token_secret: MYAPPTOKENSECRET,
},
method: 'post',
url: 'https://api.twitter.com/oauth/request_token',
form: {
'oauth_callback': MY_WHITELISTED_CALLBACK_URL,
}
};
request(options, function(error, response, data) {
console.log(data);
});
Trying to authenticate users with twitter.
I'm creating a post request to oauth/request_token as described here. But I keep getting this error:
error: [ { message: 'Sorry, that page does not exist', code: 34 } ]