You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ScrapeBadger Twitter API provides 37+ endpoints for tweets, users, lists, communities, trends, geographic places, and real-time stream monitoring. All methods are available under client.twitter.
Usage Examples
Search Tweets
import{ScrapeBadger}from"scrapebadger";constclient=newScrapeBadger({apiKey: "your-api-key"});// Basic search (returns first page)constresults=awaitclient.twitter.tweets.search("python programming");for(consttweetofresults.data){console.log(`@${tweet.username}: ${tweet.text}`);}// Paginate manuallyif(results.hasMore){constnextPage=awaitclient.twitter.tweets.search("python programming",{cursor: results.nextCursor,});}// Automatic pagination with async iteratorsforawait(consttweetofclient.twitter.tweets.searchAll("python",{maxItems: 100})){console.log(tweet.text);}// Collect all results into an arrayimport{collectAll}from"scrapebadger";consttweets=awaitcollectAll(client.twitter.tweets.searchAll("python",{maxItems: 100}));console.log(`Fetched ${tweets.length} tweets`);
User Operations
// Get user by usernameconstuser=awaitclient.twitter.users.getByUsername("elonmusk");// Get user by IDconstuserById=awaitclient.twitter.users.getById("44196397");// Get extended profile infoconstabout=awaitclient.twitter.users.getAbout("elonmusk");console.log(`Account based in: ${about.account_based_in}`);console.log(`Username changes: ${about.username_changes}`);// Get followersconstfollowers=awaitclient.twitter.users.getFollowers("elonmusk");for(constfolloweroffollowers.data){console.log(`@${follower.username}`);}// Iterate through all followersforawait(constfollowerofclient.twitter.users.getFollowersAll("elonmusk",{maxItems: 1000,})){console.log(follower.username);}// Search usersconstusers=awaitclient.twitter.users.search("python developer");
Lists
// Get list detailsconstlist=awaitclient.twitter.lists.getDetail("123456");console.log(`${list.name}: ${list.member_count} members`);// Get list tweetsconsttweets=awaitclient.twitter.lists.getTweets("123456");// Get list membersconstmembers=awaitclient.twitter.lists.getMembers("123456");// Search for listsconstlists=awaitclient.twitter.lists.search("tech leaders");
Communities
// Get community detailsconstcommunity=awaitclient.twitter.communities.getDetail("123456");console.log(`${community.name}: ${community.member_count} members`);// Get community tweetsconsttweets=awaitclient.twitter.communities.getTweets("123456",{tweetType: "Latest",});// Search communitiesconstcommunities=awaitclient.twitter.communities.search("python developers");
Trends
// Get trending topicsconsttrends=awaitclient.twitter.trends.getTrends();for(consttrendoftrends.data){console.log(`${trend.name}: ${trend.tweet_count||"N/A"} tweets`);}// Get trends by categoryconstnewsTrends=awaitclient.twitter.trends.getTrends({category: "news",});// Get trends for a specific locationconstusTrends=awaitclient.twitter.trends.getPlaceTrends(23424977);// US WOEIDconsole.log(`Trends in ${usTrends.name}:`);for(consttrendofusTrends.trends){console.log(` - ${trend.name}`);}// Get available locationsconstlocations=awaitclient.twitter.trends.getAvailableLocations();
Geographic Places
// Search for placesconstplaces=awaitclient.twitter.geo.search({query: "San Francisco"});for(constplaceofplaces.data){console.log(`${place.full_name} (${place.place_type})`);}// Search by coordinatesconstnearby=awaitclient.twitter.geo.search({lat: 37.7749,long: -122.4194,granularity: "city",});// Get place detailsconstplace=awaitclient.twitter.geo.getDetail("5a110d312052166f");
Stream Monitoring
Real-time tweet monitoring with WebSocket streaming and webhook delivery.
import{ScrapeBadger,WebSocketStreamError}from"scrapebadger";constclient=newScrapeBadger({apiKey: "your-api-key"});// Create a monitorconstmonitor=awaitclient.twitter.stream.createMonitor({name: "Tech Leaders",usernames: ["elonmusk","naval","sama"],pollIntervalSeconds: 10,webhookUrl: "https://example.com/webhook",});console.log(`Created: ${monitor.id}, tier: ${monitor.pricing_tier}`);console.log(`Credits/hr: ${monitor.estimated_credits_per_hour}`);// List monitorsconst{ monitors, total }=awaitclient.twitter.stream.listMonitors({status: "active"});console.log(`${total} active monitors`);// Pause / resumeawaitclient.twitter.stream.pauseMonitor(monitor.id);awaitclient.twitter.stream.resumeMonitor(monitor.id);// Deleteawaitclient.twitter.stream.deleteMonitor(monitor.id);