Skip to content

Instantly share code, notes, and snippets.

@popomore
Created May 26, 2013 16:26
Show Gist options
  • Save popomore/5653254 to your computer and use it in GitHub Desktop.
Save popomore/5653254 to your computer and use it in GitHub Desktop.
var https = require('https');
var Base64 = require('js-base64').Base64; // can use other base64 implement
var twitterConsumerKey = 'your consumer key';
var twitterConsumerSecret = 'your consumer secret';
var encodedBearerToken = Base64.encode(twitterConsumerKey + ':' + twitterConsumerSecret);
var options = {
hostname: 'api.twitter.com',
path: '/oauth2/token',
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
'Authorization': 'Basic ' + encodedBearerToken
},
method: 'POST'
};
var req = https.request(options, function(res) {
var data = '';
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function() {
console.log(data.toString());
});
});
req.write('grant_type=client_credentials');
req.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment