Registry / http-networking / twitter-api-client

twitter-api-client

JSON →
library0.10.22jsnpmunverified

The `twitter-api-client` package, currently at version 1.6.1, provides a promise-based Node.js client for interacting with the Twitter API. It aims to cover approximately 90% of official Twitter API endpoints and offers full TypeScript typing for both query parameters and responses, along with an inbuilt in-memory cache to manage Twitter's rate limits effectively. While functional and actively maintained for bug fixes, the project has announced it will not receive further feature development. Developers are explicitly advised by the package maintainers to transition to the official Twitter API TypeScript SDK for new projects or ongoing development due to this package's maintenance-only status. This client was previously a robust community-driven alternative known for its ease of use and comprehensive API coverage.

npm install twitter-api-client
INSTALL
IMPORT
SIG · TWITTER-API-CLIENT
T
twitter-api-client
http-networkingjavascriptv0.10.22
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TwitterClient
import { TwitterClient } from 'twitter-api-client';
import TwitterClient from 'twitter-api-client';
The main client class uses a named export, not a default export.
TwitterClient
const { TwitterClient } = require('twitter-api-client');
const TwitterClient = require('twitter-api-client');
For CommonJS environments, ensure you destructure the named export from the module.
TwitterClientOptions
import type { TwitterClientOptions } from 'twitter-api-client';
Import for TypeScript users to type the client configuration object.

Demonstrates how to initialize the TwitterClient with API credentials (using environment variables for security) and perform basic API calls like user search and trend discovery, including an example of cache configuration.

import { TwitterClient } from 'twitter-api-client'; const twitterClient = new TwitterClient({ apiKey: process.env.TWITTER_API_KEY ?? '', apiSecret: process.env.TWITTER_API_SECRET ?? '', accessToken: process.env.TWITTER_ACCESS_TOKEN ?? '', accessTokenSecret: process.env.TWITTER_ACCESS_TOKEN_SECRET ?? '' }); async function fetchData() { try { // Search for a user const users = await twitterClient.accountsAndUsers.usersSearch({ q: 'twitterDev', count: 1 }); console.log('User Search Result:', users[0]?.screen_name); // Get local trends const trends = await twitterClient.trends.trendsAvailable(); console.log('Available Trends WOEIDs:', trends.map(t => t.woeid)); // Example with caching configuration const cachedClient = new TwitterClient({ apiKey: process.env.TWITTER_API_KEY ?? '', apiSecret: process.env.TWITTER_API_SECRET ?? '', accessToken: process.env.TWITTER_ACCESS_TOKEN ?? '', accessTokenSecret: process.env.TWITTER_ACCESS_TOKEN_SECRET ?? '', ttl: 60, // seconds. Cache data for 60 seconds disableCache: false // Ensure cache is enabled }); const cachedUsers = await cachedClient.accountsAndUsers.usersSearch({ q: 'cachedUser' }); console.log('Cached User Search Result:', cachedUsers.length); } catch (error) { console.error('API call failed:', error); } } fetchData();
Debug
Known issues
deprecatedThe `twitter-api-client` package is in maintenance mode and no longer receives feature updates. The maintainers explicitly recommend transitioning to the official Twitter API TypeScript SDK.
fix
For new projects or active development, migrate to the official `twitter-api-sdk` package. This client will only receive critical bug fixes and security patches.
affects: >=1.0.0
gotchaIncorrect or missing Twitter API credentials (`apiKey`, `apiSecret`, `accessToken`, `accessTokenSecret`) will lead to authentication failures and prevent any API interaction.
fix
Ensure all four authentication parameters are correctly obtained from your Twitter Developer account and securely passed during `TwitterClient` instantiation. Verify that your app has the necessary permissions for the API endpoints you intend to use.
affects: *
gotchaAlthough the client has an inbuilt cache, improper handling of Twitter's rate limits can still result in temporary API blocking or `Rate limit exceeded` errors.
fix
Utilize the client's `ttl` configuration for caching to reduce redundant requests. For high-volume applications, consider implementing more robust rate-limit handling, such as observing `x-rate-limit` headers in responses and introducing exponential backoff for retries.
affects: *
Errors
Common errors & fixes
Error: Could not authenticate you.
One or more of the Twitter API authentication credentials (apiKey, apiSecret, accessToken, accessTokenSecret) are incorrect or invalid.
fix
Verify that your API Key, API Secret, Access Token, and Access Token Secret are accurately copied from your Twitter Developer Portal and passed to the `TwitterClient` constructor. Ensure there are no leading/trailing spaces or typos.
Rate limit exceeded
Your application has made too many requests to a specific Twitter API endpoint within a defined time window.
fix
Configure the `ttl` option for the `TwitterClient` to enable the in-memory cache, reducing duplicate requests. Alternatively, pause or delay subsequent requests to adhere to Twitter's rate limit guidelines for the affected endpoint.
TypeError: twitterClient.accountsAndUsers.usersSearch is not a function
Attempting to call an API method that does not exist or is incorrectly cased/namespaced.
fix
Consult the `REFERENCES.md` file in the project's GitHub repository to confirm the exact method names and their hierarchical structure. Ensure you are using the correct casing (e.g., `usersSearch` not `UsersSearch`).
Upgrade
Version history
0.10.22latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
20 hits · last 30 days
node
16
OpenAI (training)
2
Resources
twitter-api-client — npm install twitter-api-client · libregistry