Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including get-twitter-bearer-token with all npm packages installed. Try it out:

var getTwitterBearerToken = require("get-twitter-bearer-token")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

get-twitter-bearer-token v1.0.0

Get twitter bearer_token for oAuth

get-twitter-bearer-token

This is a convenience method to obtain an application bearer token for the Twitter api. It sends a request to /oauth2/token endpoint with the correctly formatted credentials (base64 encoded consumer key and secret) and headers.

This is only meant to be used once per application/token, since the token needs to be explicitly invalidated to stop working.

Install

npm i

Usage

const getBearerToken = require('get-twitter-bearer-token')

const twitter_consumer_key = 'your-consumer-key'
const twitter_consumer_secret = 'your-consumer-secret'

getBearerToken(twitter_consumer_key, twitter_consumer_secret, (err, res) => {
  if (err) {
    // handle error
  } else {
  
    // bearer token
    console.log(res.body.access_token)
  }
})
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free