twttrapi-middleware
v1.0.9
Published
A module to interact with the Twitter API
Readme
twttrapi-middleware
A Node.js module to interact with the Twitter API via RapidAPI's twttrapi service. This middleware provides a simplified interface for accessing Twitter data without directly using the official Twitter API.
Features
- Get tweet by ID
- Get user tweets, replies, and media
- Search tweets (latest and top results)
- Search users
- Get user profile information
- Get user followers and following lists
Installation
npm install twttrapi-middlewareRequirements
You need a RapidAPI key with access to the twttrapi service. Sign up at RapidAPI and subscribe to the twttrapi service.
Configuration
Set your RapidAPI key as an environment variable:
export RAPID_API_KEY="your-rapidapi-key"Optionally, enable debug mode:
export DEBUG=trueUsage
import TwttrApi from "twttrapi-middleware";
// Get instance (singleton pattern)
const twttr = TwttrApi.getInstance();
// Example: Get a tweet by ID
twttr.getTweetById('1907254694163980405')
.then(tweet => console.log(tweet))
.catch(error => console.error(error));
// Example: Get a user's tweets
twttr.getUserTweets('username')
.then(tweets => console.log(tweets))
.catch(error => console.error(error));API Reference
TwttrApi.getInstance()
Returns the singleton instance of the TwttrApi class.
Methods
All methods return a Promise that resolves to the requested data or an error response.
getTweetById(id: string): Get a tweet by its IDgetUserTweets(username: string): Get tweets from a usergetUserReplies(username: string): Get replies from a usergetUserMedia(username: string): Get media tweets from a usersearchTop(query: string): Search top tweets for a querysearchLatest(query: string): Search latest tweets for a querysearchUsers(query: string): Search users by querygetUser(username: string): Get a user's profile informationgetUserFollowers(username: string): Get a user's followersgetUserFollowing(username: string): Get accounts a user is following
Response Types
The module primarily returns Tweet, User, and Media objects or ErrorResponse if an error occurs.
Development
# Install dependencies
npm install
# Build
npm run build
# Run tests
npm test
# Run in development mode
npm run devLicense
MIT © dcSpark
