Created
November 29, 2017 00:44
get bearer token from Twitter REST API for application-only authentication
This file contains hidden or 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
require('dotenv').config(); | |
const request = require('request'); | |
const credentials = `${process.env.CONSUMER_KEY}:${process.env.CONSUMER_SECRET}`; | |
const credentialsBase64Encoded = new Buffer(credentials).toString('base64'); | |
request({ | |
url: 'https://api.twitter.com/oauth2/token', | |
method:'POST', | |
headers: { | |
'Authorization': `Basic ${credentialsBase64Encoded}`, | |
'Content-Type':'application/x-www-form-urlencoded;charset=UTF-8' | |
}, | |
body: 'grant_type=client_credentials' | |
}, function(err, resp, body) { | |
console.log(body); // the bearer token ... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@skaterdav85 Nice handy snippet for OAuth 2