📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP
Socket
Sign inDemoInstall
Socket

twitter-api-v2

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

twitter-api-v2

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

1.22.0
latest
Source
npm
Version published
Weekly downloads
152K
1.46%
Maintainers
1
Weekly downloads
 
Created

What is twitter-api-v2?

The twitter-api-v2 npm package is a comprehensive library for interacting with the Twitter API v2. It allows developers to perform a wide range of actions such as posting tweets, retrieving user information, managing direct messages, and more. The package is designed to be easy to use and supports both REST and streaming APIs.

What are twitter-api-v2's main functionalities?

Posting a Tweet

This feature allows you to post a tweet to your Twitter account. The code sample demonstrates how to initialize the TwitterApi client with an access token and post a tweet saying 'Hello, world!'.

const { TwitterApi } = require('twitter-api-v2');
const client = new TwitterApi('YOUR_ACCESS_TOKEN');

async function postTweet() {
  const tweet = await client.v2.tweet('Hello, world!');
  console.log(tweet);
}

postTweet();

Fetching User Information

This feature allows you to fetch information about a specific Twitter user by their username. The code sample shows how to retrieve and log the user information for the 'TwitterDev' account.

const { TwitterApi } = require('twitter-api-v2');
const client = new TwitterApi('YOUR_ACCESS_TOKEN');

async function getUserInfo() {
  const user = await client.v2.userByUsername('TwitterDev');
  console.log(user);
}

getUserInfo();

Streaming Tweets

This feature allows you to stream tweets in real-time based on certain criteria. The code sample demonstrates how to set up a stream to listen for tweets and log the tweet data as it comes in.

const { TwitterApi } = require('twitter-api-v2');
const client = new TwitterApi('YOUR_ACCESS_TOKEN');

async function streamTweets() {
  const stream = await client.v2.searchStream({ 'tweet.fields': ['author_id'] });
  for await (const { data } of stream) {
    console.log(data);
  }
}

streamTweets();

Other packages similar to twitter-api-v2

Keywords

twitter

FAQs

Package last updated on 24 Mar 2025

Did you know?

Socket

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