Skip to content

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

Twitter Scraper API by ScrapeBadger

Get API key Docs MCP server Pricing

Twitter Scraper API

Get Twitter/X data as JSON from a simple REST API, without an X developer account or its monthly tiers. The Twitter Scraper API covers advanced tweet search with every X search operator, tweet details, replies, quotes and retweeters, user profiles, timelines, followers and followings, mentions, lists, communities, Spaces, trends and places. This repo has a runnable Python, Node.js and cURL example for the main endpoints and the real response each one returned.

What does a Twitter scraper do?

A Twitter scraper collects public data from X (Twitter), such as tweets, replies, likes, retweets, user profiles and follower lists, and returns it as structured data. People use it for social listening, brand monitoring, research datasets and trading signals. With this API you send a search query, tweet ID or username and get JSON back, paying per request instead of a monthly X API tier.

Contents

Quick start

  1. Create a free ScrapeBadger account. You get 1,000 free credits, no card needed.

  2. Copy your API key from the dashboard and export it:

    export SCRAPEBADGER_API_KEY="your_api_key"
  3. Make your first request: search tweets.

cURL

curl -sS --max-time 120 -G "https://scrapebadger.com/v1/twitter/tweets/advanced_search" \
  -H "X-API-Key: $SCRAPEBADGER_API_KEY" \
  --data-urlencode 'query=from:NASA filter:media' \
  --data-urlencode 'query_type=Latest' \
  --data-urlencode 'count=10'

Python (pip install requests)

import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

response = requests.get(
    "https://scrapebadger.com/v1/twitter/tweets/advanced_search",
    headers={"X-API-Key": API_KEY},
    params={
        "query": "from:NASA filter:media",
        "query_type": "Latest",
        "count": 10,
    },
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js (18+, no dependencies)

const params = new URLSearchParams({
  query: 'from:NASA filter:media',
  query_type: 'Latest',
  count: '10',
});

const response = await fetch(`https://scrapebadger.com/v1/twitter/tweets/advanced_search?${params}`, {
  headers: { 'X-API-Key': process.env.SCRAPEBADGER_API_KEY },
  signal: AbortSignal.timeout(120000),
});
if (!response.ok) {
  throw new Error(`HTTP ${response.status}: ${await response.text()}`);
}
console.log(JSON.stringify(await response.json(), null, 2));

Every endpoint below has the same three versions in examples/, and the real response it returned is in output-samples/.

Endpoints

Base URL: https://scrapebadger.com. Authenticate with the X-API-Key header. Credits are charged only for successful requests.

Endpoint What it returns Credits per request Docs
GET /v1/twitter/tweets/ Get tweets by IDs 1 + 1 per result Docs
GET /v1/twitter/tweets/tweet/{tweet_id} Get tweet details 1 + 1 per result Docs
GET /v1/twitter/tweets/tweet/{tweet_id}/retweeters Get tweet retweeters 1 + 1 per result Docs
GET /v1/twitter/tweets/tweet/{tweet_id}/replies Get tweet replies 1 + 1 per result Docs
GET /v1/twitter/tweets/tweet/{tweet_id}/favoriters Get tweet favoriters 1 + 1 per result Docs
GET /v1/twitter/tweets/tweet/{tweet_id}/similar Get similar tweets 1 + 1 per result Docs
GET /v1/twitter/tweets/advanced_search Advanced tweet search 1 + 1 per result Docs
GET /v1/twitter/tweets/tweet/{tweet_id}/edit_history Get tweet edit history 1 + 1 per result Docs
GET /v1/twitter/tweets/tweet/{tweet_id}/community_notes Get community notes 1 + 1 per result Docs
GET /v1/twitter/tweets/tweet/{tweet_id}/quotes Get tweet quotes 1 + 1 per result Docs
GET /v1/twitter/tweets/article/{article_id} Get article by ID 1 + 1 per result Docs
GET /v1/twitter/users/batch_by_ids Batch get users by IDs 1 + 1 per result Docs
GET /v1/twitter/users/batch_by_usernames Batch get users by usernames 1 + 1 per result Docs
GET /v1/twitter/users/{user_id}/by_id Get user by ID 1 + 1 per result Docs
GET /v1/twitter/users/{username}/by_username Get user by username 1 + 1 per result Docs
GET /v1/twitter/users/{username}/latest_tweets Get user tweets 1 + 1 per result Docs
GET /v1/twitter/users/{username}/followers Get user followers 1 + 1 per result Docs
GET /v1/twitter/users/{username}/followings Get user following 1 + 1 per result Docs
GET /v1/twitter/users/{user_id}/subscriptions Get user subscriptions 1 + 1 per result Docs
GET /v1/twitter/users/search_users Search users 1 + 1 per result Docs
GET /v1/twitter/users/{username}/mentions Get user mentions 1 + 1 per result Docs
GET /v1/twitter/users/{user_id}/articles Get user articles 1 + 1 per result Docs
GET /v1/twitter/lists/{list_id}/detail Get list details 1 + 1 per result Docs
GET /v1/twitter/lists/{list_id}/tweets Get list tweets 1 + 1 per result Docs
GET /v1/twitter/lists/{list_id}/search_tweets Search list tweets 1 + 1 per result Docs
GET /v1/twitter/communities/search_tweets Search tweets across communities 1 + 1 per result Docs
GET /v1/twitter/communities/{community_id} Get community details 1 + 1 per result Docs
GET /v1/twitter/communities/{community_id}/tweets Get community tweets 1 + 1 per result Docs
GET /v1/twitter/communities/search Search communities 1 + 1 per result Docs
GET /v1/twitter/trends/ Get trending topics 1 + 1 per result Docs
GET /v1/twitter/trends/place/{woeid} Get trends by location 1 + 1 per result Docs
GET /v1/twitter/geo/search Search places 1 + 1 per result Docs
GET /v1/twitter/geo/places/{place_id} Get place details 1 + 1 per result Docs
GET /v1/twitter/spaces/broadcast/{broadcast_id} Get broadcast details 1 + 1 per result Docs
GET /v1/twitter/spaces/{space_id} Get Space details 1 + 1 per result Docs

Common parameters

Parameter Description Default
cursor Cursor from the previous response (next_cursor), to get the next page of a list endpoint.
count Results per page where supported (advanced search, mentions, community tweets, trends).

Examples by endpoint

Each example prints the JSON response. The Python versions are below; Node.js and cURL versions are linked under each one.

Search tweets

Search tweets with advanced options.

GET /v1/twitter/tweets/advanced_search · Credits: 1 + 1 per result · Docs

Parameter Required Type Default Description
query Yes string For advanced search, any X search query, including operators such as from:, to:, since:, until:, min_faves:, lang:, filter:media and -filter:replies
query_type string Latest (newest first) or Top (X's ranking)
count integer Results per page where supported (advanced search, mentions, community tweets, trends).
cursor string Cursor from the previous response (next_cursor), to get the next page of a list endpoint.
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

response = requests.get(
    "https://scrapebadger.com/v1/twitter/tweets/advanced_search",
    headers={"X-API-Key": API_KEY},
    params={
        "query": "from:NASA filter:media",
        "query_type": "Latest",
        "count": 10,
    },
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (30 KB)

Get a tweet

Get detailed information about a specific tweet.

GET /v1/twitter/tweets/tweet/{tweet_id} · Credits: 1 + 1 per result · Docs

Parameter Required Type Default Description
tweet_id Yes string Tweet ID, the number at the end of a tweet URL, e.g. 20
cursor string Cursor from the previous response (next_cursor), to get the next page of a list endpoint.
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

tweet_id = "20"

response = requests.get(
    f"https://scrapebadger.com/v1/twitter/tweets/tweet/{tweet_id}",
    headers={"X-API-Key": API_KEY},
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (1 KB)

Get tweets by IDs

Get multiple tweets by their IDs.

GET /v1/twitter/tweets/ · Credits: 1 + 1 per result · Docs

Parameter Required Type Default Description
tweets Yes string
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

response = requests.get(
    "https://scrapebadger.com/v1/twitter/tweets/",
    headers={"X-API-Key": API_KEY},
    params={
        "tweets": "20,2127782287756386468",
    },
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (5 KB)

Get replies to a tweet

Get replies to a specific tweet.

GET /v1/twitter/tweets/tweet/{tweet_id}/replies · Credits: 1 + 1 per result · Docs

Parameter Required Type Default Description
tweet_id Yes string Tweet ID, the number at the end of a tweet URL, e.g. 20
cursor string Cursor from the previous response (next_cursor), to get the next page of a list endpoint.
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

tweet_id = "20"

response = requests.get(
    f"https://scrapebadger.com/v1/twitter/tweets/tweet/{tweet_id}/replies",
    headers={"X-API-Key": API_KEY},
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (77 KB)

Get quote tweets

Get tweets that quote a specific tweet.

GET /v1/twitter/tweets/tweet/{tweet_id}/quotes · Credits: 1 + 1 per result · Docs

Parameter Required Type Default Description
tweet_id Yes string Tweet ID, the number at the end of a tweet URL, e.g. 20
cursor string Cursor from the previous response (next_cursor), to get the next page of a list endpoint.
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

tweet_id = "20"

response = requests.get(
    f"https://scrapebadger.com/v1/twitter/tweets/tweet/{tweet_id}/quotes",
    headers={"X-API-Key": API_KEY},
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (40 KB)

Get a user profile

Get user profile by username.

GET /v1/twitter/users/{username}/by_username · Credits: 1 + 1 per result · Docs

Parameter Required Type Default Description
username Yes string X handle without @, e.g. NASA
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

username = "NASA"

response = requests.get(
    f"https://scrapebadger.com/v1/twitter/users/{username}/by_username",
    headers={"X-API-Key": API_KEY},
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (1 KB)

Get a user's latest tweets

Get latest tweets from a specific user.

GET /v1/twitter/users/{username}/latest_tweets · Credits: 1 + 1 per result · Docs

Parameter Required Type Default Description
username Yes string X handle without @, e.g. NASA
cursor string Cursor from the previous response (next_cursor), to get the next page of a list endpoint.
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

username = "NASA"

response = requests.get(
    f"https://scrapebadger.com/v1/twitter/users/{username}/latest_tweets",
    headers={"X-API-Key": API_KEY},
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (57 KB)

Get several profiles at once

Get multiple user profiles by their usernames (comma-separated).

GET /v1/twitter/users/batch_by_usernames · Credits: 1 + 1 per result · Docs

Parameter Required Type Default Description
usernames Yes string
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

response = requests.get(
    "https://scrapebadger.com/v1/twitter/users/batch_by_usernames",
    headers={"X-API-Key": API_KEY},
    params={
        "usernames": "NASA,SpaceX,esa",
    },
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (6 KB)

Get tweets mentioning a user

Get tweets mentioning a specific user.

GET /v1/twitter/users/{username}/mentions · Credits: 1 + 1 per result · Docs

Parameter Required Type Default Description
username Yes string X handle without @, e.g. NASA
count integer Results per page where supported (advanced search, mentions, community tweets, trends).
cursor string Cursor from the previous response (next_cursor), to get the next page of a list endpoint.
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

username = "NASA"

response = requests.get(
    f"https://scrapebadger.com/v1/twitter/users/{username}/mentions",
    headers={"X-API-Key": API_KEY},
    params={
        "count": 10,
    },
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (30 KB)

Search users

Search for users by query.

GET /v1/twitter/users/search_users · Credits: 1 + 1 per result · Docs

Parameter Required Type Default Description
query Yes string For advanced search, any X search query, including operators such as from:, to:, since:, until:, min_faves:, lang:, filter:media and -filter:replies
cursor string Cursor from the previous response (next_cursor), to get the next page of a list endpoint.
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

response = requests.get(
    "https://scrapebadger.com/v1/twitter/users/search_users",
    headers={"X-API-Key": API_KEY},
    params={
        "query": "space agency",
    },
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (35 KB)

Get trends for a location

Get trending topics for a specific location (WOEID).

GET /v1/twitter/trends/place/{woeid} · Credits: 1 + 1 per result · Docs

Parameter Required Type Default Description
woeid Yes string Yahoo Where On Earth ID of a place; 1 is worldwide, 23424977 the United States
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

woeid = "23424977"

response = requests.get(
    f"https://scrapebadger.com/v1/twitter/trends/place/{woeid}",
    headers={"X-API-Key": API_KEY},
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (7 KB)

Search communities

Search for communities by query.

GET /v1/twitter/communities/search · Credits: 1 + 1 per result · Docs

Parameter Required Type Default Description
query Yes string For advanced search, any X search query, including operators such as from:, to:, since:, until:, min_faves:, lang:, filter:media and -filter:replies
cursor string Cursor from the previous response (next_cursor), to get the next page of a list endpoint.
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

response = requests.get(
    "https://scrapebadger.com/v1/twitter/communities/search",
    headers={"X-API-Key": API_KEY},
    params={
        "query": "AI",
    },
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (8 KB)

Example output

A real response from GET /v1/twitter/tweets/advanced_search, trimmed to the first items of each list. The full response is in output-samples/advanced-search.json.

{
  "data": [
    {
      "id": "2127855687975747659",
      "text": "As December arrives, 2026 comes to a close. Here’s what’s up in the sky as we wrap up the year:\n- Our planet gives Europa Clipper a boost\n- The Geminids decorate the night\n- The winter solstice occurs on Dec. 21\n\nhttps:/…",
      "full_text": "As December arrives, 2026 comes to a close. Here’s what’s up in the sky as we wrap up the year:\n- Our planet gives Europa Clipper a boost\n- The Geminids decorate the night\n- The winter solstice occurs on Dec. 21\n\nhttps:/…",
      "created_at": "Tue Dec 01 20:01:44 +0000 2026",
      "lang": "en",
      "user_id": "11348282",
      "username": "NASA",
      "user_name": "NASA",
      "user_profile_image_url": "https://pbs.twimg.com/profile_images/1321163587679784960/0ZxKlEKB_normal.jpg",
      "user_description": "Making the seemingly impossible, possible. ✨",
      "user_location": "Pale Blue Dot",
      "user_url": "https://t.co/9NkQJKAnuU",
      "user_followers_count": 92027864,
      "user_following_count": 115,
      "user_tweet_count": 74604,
      "user_verified": false,
      "user_is_blue_verified": true,
      "user_created_at": "Wed Dec 19 20:20:32 +0000 2007",
      "favorite_count": 783,
      "retweet_count": 135,
      "reply_count": 52,
      "quote_count": 10,
      "view_count": "255501",
      "bookmark_count": 46,
      "favorited": false,
      "retweeted": false,
      "bookmarked": false,
      "possibly_sensitive": false,
      "is_quote_status": false,
      "is_retweet": false,
      "conversation_id": "2127855687975747659",
      "in_reply_to_status_id": null,
      "in_reply_to_user_id": null,
      "in_reply_to_screen_name": null,
      "display_text_range": [
        0
      ],
      "media": [
        {
          "media_key": "2127855498821042176",
          "type": "video",
          "url": "https://pbs.twimg.com/media/HYepeBHWsAAgYHz.jpg",
          "preview_image_url": "https://pbs.twimg.com/media/HYepeBHWsAAgYHz.jpg",
          "width": 1920,
          "height": 1080,
          "duration_ms": 182665,
          "view_count": null,
          "alt_text": null
        }
      ],
      "urls": [
        {
          "url": "https://t.co/ZFRaXBwHKI",
          "expanded_url": "https://go.nasa.gov/4zZsY7k",
          "display_url": "go.nasa.gov/4zZsY7k",
          "unwound_url": null
        }
  …

Use it with AI agents (MCP)

ScrapeBadger runs a hosted MCP server, so Claude, Cursor, ChatGPT and other agents can call the Twitter/X endpoints as tools, with no code.

  • Claude (claude.ai or Claude Desktop): Settings → Connectors → Add custom connector → https://mcp.scrapebadger.com/mcp, then sign in. No API key needed.
  • Cursor, VS Code, Windsurf and other clients: add this server to your MCP config:
{
  "mcpServers": {
    "scrapebadger": {
      "url": "https://mcp.scrapebadger.com/mcp?apis=twitter",
      "headers": { "Authorization": "Bearer YOUR_SCRAPEBADGER_API_KEY" }
    }
  }
}

Then ask:

Find the 20 most-liked tweets about "web scraping" from the last 7 days and summarise what people are asking about.

Setup guides for each client are in the MCP docs.

Use cases

Use case What you collect Endpoints
Brand and keyword monitoring Every new tweet that mentions your brand, product or keywords Search tweets, Get tweets mentioning a user
Social listening and sentiment Replies and quote tweets around a launch or announcement Get replies to a tweet, Get quote tweets, Search tweets
Influencer and account research Profiles, follower counts and recent tweets for a list of accounts Get several profiles at once, Get a user profile, Get a user's latest tweets, Search users
Research datasets Tweets for a query and time range, with engagement counts Search tweets, Get tweets by IDs
Trend tracking What's trending by country or city Get trends for a location
Community research X Communities for a topic and what members post Search communities

Pricing

Most Twitter endpoints are billed per call plus per item returned, so a page of 20 tweets costs about 21 credits. Set count where an endpoint supports it to bound the cost of a call.

  • Each endpoint's credit cost is listed in the endpoints table.
  • Only successful requests are billed. Blocked, empty and failed results cost nothing.
  • New accounts get 1,000 free credits. After that, pay as you go or pick a monthly plan. Credits on pay-as-you-go never expire.

See ScrapeBadger pricing for the price per credit on each plan.

Errors

Errors come back as JSON with a detail field (and an error code on some).

Status Meaning What to do
400 / 422 A parameter is missing or invalid Check the parameter table for the endpoint
401 Missing, invalid or expired API key Send the key in the X-API-Key header
402 Out of credits Top up or upgrade in the dashboard
403 The key can't call this API, or the request came from an IP the key doesn't allow Check the key's scopes and IP allowlist
404 The item, page or profile doesn't exist (or is no longer public) Check the ID; not billed
429 Over your account's max concurrency Wait Retry-After (1 s) and retry; run fewer calls in parallel (concurrency)
502 / 503 / 504 The target site failed or timed out on this attempt Not billed. Retry with backoff

Long calls can run asynchronously: send Prefer: respond-async and poll the returned request_id (async requests).

FAQ

Is it legal to scrape Twitter/X?

This API returns public tweets and profiles that anyone can see on X. Collecting public data is generally lawful in most jurisdictions, but tweets and profiles contain personal data, so check the rules that apply to how you store and use them (for example GDPR), and ask a lawyer if you're unsure. Protected accounts are not available.

How is this different from the official X API?

There's no developer account, no app review and no monthly tier: you pay per successful request, for the calls you make. The response format is close to X's own, so moving from the official API is straightforward.

How much does it cost?

Most endpoints cost 1 credit per call plus 1 credit per item returned, and only successful requests are billed. You get 1,000 free credits when you sign up, then pay as you go or pick a plan on the pricing page.

Can I search old tweets?

Yes. Advanced search accepts X's search operators, including since: and until: dates, so you can search any period, not just the last 7 days.

How fast is it, and are there rate limits?

Most calls answer in under a second or two. There's no per-minute cap: you can run as many requests in parallel as your plan's max concurrency allows, and a request over it gets 429 without being billed. For real-time feeds, see the Twitter Streaming API.

Other languages

These examples use plain HTTP. Official SDKs wrap every endpoint with types and retries:

Language Repository Install
Python scrape-badger/scrapebadger-python pip install scrapebadger
Node.js / TypeScript scrape-badger/scrapebadger-node npm install scrapebadger
Go scrape-badger/scrapebadger-go
Java scrape-badger/scrapebadger-java
C# scrape-badger/scrapebadger-csharp
PHP scrape-badger/scrapebadger-php
Ruby scrape-badger/scrapebadger-ruby
Rust scrape-badger/scrapebadger-rust
Kotlin scrape-badger/scrapebadger-kotlin
Swift scrape-badger/scrapebadger-swift
Dart scrape-badger/scrapebadger-dart
C++ scrape-badger/scrapebadger-cpp

There is also a CLI (pip install scrapebadger-cli) and an n8n node.

Related scrapers

Learn more

Disclaimer

ScrapeBadger is an independent tool and is not affiliated with, endorsed by, or in any way officially connected with X Corp. (formerly Twitter, Inc.) or any of its subsidiaries or affiliates. The names Twitter, X, and related trademarks are the property of their respective owners. This repository only covers publicly available data. You are responsible for how you use the data you collect and for following the laws that apply to you.

License

MIT. The examples are free to copy into your own projects.