Created
May 26, 2013 16:26
-
-
Save popomore/5653254 to your computer and use it in GitHub Desktop.
Twitter OAuth2 https://dev.twitter.com/docs/auth/application-only-auth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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