
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
twitter-api-v2
Advanced tools
WIP
Twitter api v2 (and v1 in the future) client for node
The main libraries (twit/twitter) were not updated in a while
I don't think a Twitter library need many dependencies
They caused me some frustration:
import TwitterApi, { TwitterErrors } from 'twitter-api-v2';
// bearer token auth (with V2)
const twitterClient = new TwitterApi('<YOUR_APP_USER_TOKEN>');
// token auth
const twitterClient = new TwitterApi({
appKey: '<YOUR-TWITTER-APP-TOKEN>',
appSecret: '<YOUR-TWITTER-APP-SECERT>',
accesToken: '<YOUR-TWITTER-APP-TOKEN>',
accessSecret: '<YOUR-TWITTER-APP-SECERT>',
});
// link auth
const twitterClient = new TwitterApi({
appKey: '<YOUR-TWITTER-APP-TOKEN>',
appSecret: '<YOUR-TWITTER-APP-SECERT>',
});
const authLink = await twitterClient.generateAuthLink();
// ... redirected to https://website.com?oauth_token=XXX&oauth_verifier=XXX
const { usertoken, userSecret } = twitterClient.login('<THE_OAUTH_TOKEN>', '<THE_OAUTH_VERIFIER>');
// Tell typescript it's a readonly app
const twitterClient = new TwitterApi(xxx).readOnly;
// Search for tweets
const tweets = await twitterClient.tweets.search('nodeJS', { max_results: 100 });
// Or do it your way (however, with no result typed)
const tweets = await twitterClient.v2.get('tweets/search/recent', {query: 'nodeJS', max_results: '100'});
const tweets = await twitterClient.get('https://api.twitter.com/2/tweets/search/recent?query=nodeJS&max_results=100');
// Auto-paginate
// (also checks if rate limits will be enough after the first request)
const manyTweets = await twitterClient.tweets.search('nodeJS').fetchLast(10000);
// Manage errors
try {
const manyTweets = await twitterClient.tweets.search('nodeJS').fetchLast(100000000);
} catch(e) {
if (e.errorCode === TwitterErrors.RATE_LIMIT_EXCEEDED) {
console.log('please try again later!');
} else {
throw e;
}
}
FAQs
Strongly typed, full-featured, light, versatile yet powerful Twitter API v1.1 and v2 client for Node.js.
The npm package twitter-api-v2 receives a total of 87,361 weekly downloads. As such, twitter-api-v2 popularity was classified as popular.
We found that twitter-api-v2 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.