Forked from elmariachi111/createBearerToken.js
Last active
September 30, 2018 13:28
-
-
Save iamdtang/ff6f8c12adc0c733f521744f6e06a1b6 to your computer and use it in GitHub Desktop.
A Javascript file that requests a Twitter bearer token for application only authentication (https://dev.twitter.com/docs/auth/application-only-auth). Depends on mikeals request library (https://github.com/mikeal/request) (npm install request)
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 request = require("request"); | |
var key = process.env.TWITTER_CONSUMER_KEY; | |
var secret = process.env.TWITTER_CONSUMER_SECRET; | |
var cat = key + ":" + secret; | |
var credentials = new Buffer(cat).toString('base64'); | |
var url = 'https://api.twitter.com/oauth2/token'; | |
request({ | |
url: url, | |
method:'POST', | |
headers: { | |
"Authorization": "Basic " + credentials, | |
"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8" | |
}, | |
body: "grant_type=client_credentials" | |
}, function(err, resp, body) { | |
console.dir(body); // the bearer token ... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment