🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

vogel

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vogel

Straight-forward Twitter API client with OAuth support

latest
Source
npmnpm
Version
0.0.7
Version published
Weekly downloads
3
200%
Maintainers
1
Weekly downloads
 
Created
Source

Vogel

Straight-forward Twitter API client with full OAuth support (Bearer, PIN and 1.0a)

Installation

npm install --save vogel

yarn add vogel

Usage

If you want more in-depth and currently working examples, checkout example/.

Starting with no access token:

const Vogel = require('vogel')

const vogel = new Vogel({
  consumerKey: TWITTER_CONSUMER_KEY,
  consumerSecret: TWITTER_CONSUMER_SECRET,
  oauthCallback: 'http://localhost:8000/api/oauth-token'
})

const url = await vogel.getRequestToken()

// User goes to url, clicks the button, you get a request token + verifier back

// Access tokens!
// These tokens are also persisted to Vogel's scope so you don't need to send
// them with subsequent requests or manage them yourself
const {
  token,
  tokenSecret
} = await vogel.getAccessToken(requestToken, verifier)

Have an access token already:

const Vogel = require('vogel')

const vogel = new Vogel({
  consumerKey: TWITTER_CONSUMER_KEY,
  consumerSecret: TWITTER_CONSUMER_SECRET,
  accessTokenKey: TWITTER_ACCESS_TOKEN,
  accessTokenSecret: TWITTER_ACCESS_TOKEN_SECRET
})

Bearer tokens

const Vogel = require('vogel')

const vogel = new Vogel({
  consumerKey: TWITTER_CONSUMER_KEY,
  consumerSecret: TWITTER_CONSUMER_SECRET,
  bearerToken: TWITTER_BEARER_TOKEN
})

CLI / PIN-based OAuth (oob)

const Vogel = require('vogel')

const vogel = new Vogel({
  consumerKey: TWITTER_CONSUMER_KEY,
  consumerSecret: TWITTER_CONSUMER_SECRET,
  oauthCallback: 'oob'
})

const url = await vogel.getRequestToken()

// User goes to url, clicks the button, user is shown a pin

// Ask the user for the PIN and pass in
const {
  token,
  tokenSecret
} = await vogel.getAccessToken(pin)

Making requests

After you have authenticated either manually (getRequestToken() -> getAccessToken) or through passing the token, you will be able to make any request fully authenticated

get

const vogel = new Vogel({ ... })

const res = await vogel.get('/1.1/statuses/home_timeline.json', {
  query: {
    count: '200'
  }
})

// Uses node-fetch under the hood
const body = await res.json()

post

const vogel = new Vogel({ ... })

// Twitter is teasing us! We want tweet editing!
const res = await vogel.post('/1.1/statuses/update.json', {
  query: {
    status: 'hello!'
  }
})

// Uses node-fetch under the hood
const body = await res.json()

stream

coming soon?

Keywords

twitter

FAQs

Package last updated on 13 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts