twitter-api-v2 is a strongly typed, full-featured, and lightweight client for both Twitter API v1.1 and v2, designed for Node.js. Currently at version 1.29.0, it maintains an active release cadence, frequently incorporating new API features, fixes, and improvements as seen in recent updates like adding `article` tweet fields and expanding user/community fields. Its key differentiators include comprehensive TypeScript typings for all request parameters and response payloads, ensuring robust development, and a remarkable zero-dependency footprint, leading to a minimal bundle size (23kb minified+gzipped). The library provides extensive support for streaming, pagination, user-context authentication with OAuth2, and convenient media upload helpers, contrasting with other libraries that often lack strong typing or carry numerous external dependencies. It aims to provide a reliable and efficient wrapper around Twitter's evolving API.
npm install twitter-api-v2Verified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to instantiate a Twitter client with OAuth1.1, fetch user data via the v2 API, post a tweet, and listen to a sample stream, showcasing common library features.
Review the media upload methods, specifically `v2.uploadMedia` or related functions, to ensure compatibility with the updated alt text parameters and structure. Consult the changelog or documentation for specific adjustments required.
Actively monitor official Twitter/X developer documentation and announcements. Keep `twitter-api-v2` updated to the latest version, as the maintainers actively adapt to changes. Implement robust error handling for API responses.
Always verify that your application has been granted the necessary OAuth scopes for every API endpoint you intend to use. Re-authenticate or regenerate tokens if scopes need to be updated. For example, posting tweets requires 'tweet.write' scope.
Implement custom rate limit handling logic, including retries with exponential backoff. The library provides access to `x-rate-limit` headers in responses, which can be used to inform your rate limiting strategy.
Verify that your `appKey`, `appSecret`, `accessToken`, and `accessSecret` are correct, up-to-date, and have not been revoked. Regenerate them if unsure.
Check the official Twitter API documentation for the specific endpoint to determine the necessary OAuth scopes (e.g., `tweet.write`, `users.read`). Ensure your application's token has these scopes granted.
Implement rate limiting logic on your side, such as retries with exponential backoff. You can inspect `x-rate-limit` headers in the API response to determine remaining calls and reset times.
No dependency data recorded yet.