1.18.1 • Published 22 days ago

twitter-api-v2 v1.18.1

Weekly downloads
102
License
Apache-2.0
Repository
github
Last release
22 days ago

Twitter API v2

Version badge Checks badge Package size badge

Strongly typed, full-featured, light, versatile yet powerful Twitter API v1.1 and v2 client for Node.js.

Main maintainer: @alkihis -

Important Note

Twitter will significantly reduce its API capabilities by end of April (see this thread).

This change has major implications, and as a result, this library may no longer be maintained.

We are disappointed and discouraged by the recent turn of events at Twitter since the takeover by Elon Musk. We are saddened to see that much of the hard work of the past few years on the API, led by an amazing team including @andypiper, has been shelved.

For a more detailed explanation, please see this discussion.

Highlights

Ready for v2 and good ol' v1.1 Twitter API

Light: No dependencies, 23kb minified+gzipped

Bundled types for request parameters and responses

Streaming support

Pagination utils

User-context authentication with OAuth2

Media upload helpers

How to use

Install it through your favorite package manager:

yarn add twitter-api-v2
# or
npm i twitter-api-v2

Here's a quick example of usage:

import { TwitterApi } from 'twitter-api-v2';

// Instantiate with desired auth type (here's Bearer v2 auth)
const twitterClient = new TwitterApi('<YOUR_APP_USER_TOKEN>');

// Tell typescript it's a readonly app
const readOnlyClient = twitterClient.readOnly;

// Play with the built in methods
const user = await readOnlyClient.v2.userByUsername('plhery');
await twitterClient.v2.tweet('Hello, this is a test.');
// You can upload media easily!
await twitterClient.v1.uploadMedia('./big-buck-bunny.mp4');

Why?

Sometimes, you just want to quickly bootstrap an application using the Twitter API. Even though there are a lot of libraries available on the JavaScript ecosystem, they usually just provide wrappers around HTTP methods, and some of them are bloated with many dependencies.

twitter-api-v2 is meant to provide full endpoint wrapping, from method name to response data, using descriptive typings for read/write/DMs rights, request parameters and response payload.

A small feature comparison with other libs:

PackageAPI version(s)Response typingsMedia helpersPaginationSubdepsSize (gzip)Install size
twitter-api-v2v1.1, v2, labs0~23 kBtwitter-api-v2 install size badge
twitv1.151~214.5 kBtwit install size badge
twitterv1.150~182.1 kBtwitter install size badge
twitter-litev1.1, v24~5.3 kBtwitter-lite install size badge
twitter-v2v27~4.5 kBtwitter-v2 install size badge

Features

Here's everything twitter-api-v2 can do:

Basics:

  • Support for v1.1 and v2 of Twitter API
  • Make signed HTTP requests to Twitter with every auth type: OAuth 1.0a, OAuth2 (even brand new user context OAuth2!) and Basic HTTP Authorization
  • Helpers for numerous HTTP request methods (GET, POST, PUT, DELETE and PATCH), that handle query string parse & format, automatic body formatting and more
  • High-class support for stream endpoints, with easy data consumption and auto-reconnect on stream errors

Request helpers:

  • Automatic paginator for endpoints like user and tweet timelines, allowing payload consumption with modern asynchronous iterators until your rate-limit is hit
  • Convenient methods for authentication - generate auth links and ask for tokens to your users
  • Media upload with API v1.1, including long video & subtitles support, automatic media type detection, chunked upload and support for concurrent uploads
  • Dedicated methods that wraps API v1.1 & v2 endpoints, with typed arguments and fully typed responses
  • Typed errors, meaningful error messages, error enumerations for both v1.1 and v2

Type-safe first:

  • Typings for tweet, user, media entities (and more) are bundled!
  • Type-safe wrapping of dedicated methods in 3 right level: DM/Read-write/Read-only (just like Twitter API do!) - you can declare a read-only client - you will only see the methods associated with read-only endpoints

And last but not least, fully powered by native Promises.

Documentation

Learn how to use the full potential of twitter-api-v2.

Plugins

Official plugins for twitter-api-v2:

See how to use plugins here.

1.18.1

22 days ago

1.18.0

1 month ago

1.17.2

4 months ago

1.17.1

6 months ago

1.17.0

6 months ago

1.16.4

6 months ago

1.16.3

7 months ago

1.16.2

7 months ago

1.16.1

8 months ago

1.16.0

10 months ago

1.14.3

1 year ago

1.15.0

1 year ago

1.15.2

1 year ago

1.15.1

1 year ago

1.14.1

2 years ago

1.14.0

2 years ago

1.14.2

2 years ago

1.12.9

2 years ago

1.12.8

2 years ago

1.12.10

2 years ago

1.13.0

2 years ago

1.12.7

2 years ago

1.12.6

2 years ago

1.12.3

2 years ago

1.12.2

2 years ago

1.12.1

2 years ago

1.12.5

2 years ago

1.12.4

2 years ago

1.11.3

3 years ago

1.11.2

3 years ago

1.12.0

3 years ago

1.11.1

3 years ago

1.10.3

3 years ago

1.10.2

3 years ago

1.9.1

3 years ago

1.9.0

3 years ago

1.8.1

3 years ago

1.7.2

3 years ago

1.8.0

3 years ago

1.7.1

3 years ago

1.11.0

3 years ago

1.10.1

3 years ago

1.10.0

3 years ago

1.7.0

3 years ago

1.6.5

3 years ago

1.6.4

3 years ago

1.6.3

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago