I have a question. I've been trying to figure this out for the past 3 hours now, and I have no clue as to why this isn't working how i'm expecting it to. Please know that i'm still very new to Javascript, so I apologise if anything is blatantly obvious.
With this code, i'm trying to get a bearer token from Twitter, however, return body
and console.log(body)
return 2 completely different things.
When I console.log(body)
, I get the output I expect:
{"token_type":"bearer","access_token":"#####"}
However, if I return body
, I get the http request as JSON. I've pasted my code below, I hope someone will be able to help.
var request = require('request');
var enc_secret = new Buffer(twit_conkey + ':' + twit_consec).toString('base64');
var oauthOptions = {
url: 'https://api.twitter.com/oauth2/token',
headers: {'Authorization': 'Basic ' + enc_secret, 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'},
body: 'grant_type=client_credentials'
};
var oauth = request.post(oauthOptions, function(e, r, body) {
return body;
});
console.log(oauth)