Socket
Socket
Sign inDemoInstall

twitter-lite

Package Overview
Dependencies
9
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    twitter-lite

A tiny, full-featured client / server library for the Twitter API


Version published
Maintainers
1
Install size
699 kB
Created

Readme

Source

Twitter Lite npm travis

A tiny (591B), fully-featured, client & server library for the Twitter API

  • Promise-first via Async / Await
  • Up-to-date
  • Under 1kb

Installation

yarn add twitter-lite
npm install twitter-lite

Usage

  • Create an app on https://apps.twitter.com/
  • Grab the Consumer Key (API Key) and Consumer Secret (API Secret) from Keys and Access Tokens
  • Make sure you set the right access level for your app

App vs. User

Twitter has two different authentication options:

  • App: higher rate limits. Great for building your own Twitter App
  • User: lower rate limits. Great for making requests on behalf of a User.

User authentication requires:

  • consumer_key
  • consumer_secret
  • access_token_key
  • access_token_secret

App authentication requires:

  • bearer_token

App authentication is a simple header behind the scenes:

headers: {
  Authorization: `Bearer ${bearer_token}`
}

Verifying Credentials Example (User auth)

const client = new Twitter({
  subdomain: "api",
  consumer_key: "xyz" // from Twitter.
  consumer_secret: "xyz" // from Twitter.
  access_token_key: "abc" // from your User (oauth_token)
  access_token_secret: "abc" // from your User (oauth_token_secret)
})

client.get("account/verify_credentials")
.then(results => { console.log("results", results) })
.catch(console.error)

App authentication Example

const client = new Twitter({
  subdomain: "api",
  bearer_token: "Bearer ABC123XYZ" // generate a Bearer token
})

client.get("users/lookup")
.then(results => { console.log("results", results ) })
.catch(console.error)

Streams

TBD

I don't know shit about streams. If you can help make this work with streams, I would appreciate & encourage it!

Troubleshooting

API Errors

Api errors are returned (with "catch" in the Promise api or with "err" param in the callback api) as an array of errors. Thus errors described in twitter docs for example as:

 { "errors": [ { "code": 88, "message": "Rate limit exceeded" } ] }

Would return as :

 [ { "code": 88, "message": "Rate limit exceeded" } ] 

Credit

Over the years, thanks to:

Keywords

FAQs

Last updated on 16 Feb 2018

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc