get bearer token from Twitter REST API for application-only authentication
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 ... | |
}); |
This comment has been minimized.
This comment has been minimized.
Upvote |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
@skaterdav85 Nice handy snippet for OAuth 2