Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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 ...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment