# Twitter / X Scraper - Profiles, Tweets, Search & Data Export (`convertfleetdotonline/twitter-scraper`) Actor

Scrape Twitter / X profiles, tweets, hashtags, and search results at scale. Extract follower counts, engagement metrics, user bios, and full tweet history. Supports multi-strategy data collection via Apify API.

- **URL**: https://apify.com/convertfleetdotonline/twitter-scraper.md
- **Developed by:** [Hasnain Nisar](https://apify.com/convertfleetdotonline) (community)
- **Categories:** Social media, Lead generation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$1.00 / 1,000 tweet scrapeds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## Twitter / X Scraper - Profiles, Tweets, Search (No API Key)

**Scrape tweets, profiles, and search results from Twitter / X without an API key.** Multi-strategy fallback chain (syndication → Nitter mirrors → DuckDuckGo) keeps you scraping even when one path is rate-limited. Optional Twitter API v2 path for premium reliability.

### What this Twitter / X Scraper does

The actor accepts three input modes (you can mix them in a single run):

- **Profile mode** — pass usernames (`@elonmusk`, `@apify`) and get their recent tweets
- **Search mode** — pass free-form queries (`"AI agents"`, `"hiring frontend"`) and get matching tweets
- **URL mode** — pass any X / twitter.com URL: status URLs, profile URLs, or search URLs

Filter out replies and / or retweets, cap results per target, and let the actor handle anti-bot defenses with its built-in fallback strategies.

### Multi-strategy resolution

For each target, the actor tries strategies in order and returns the first that succeeds:

1. **Twitter API v2** — used automatically if `TWITTER_BEARER_TOKEN` env var is set (most reliable, recommended for production)
2. **Twitter syndication endpoint** — `syndication.twitter.com` (works for profiles, no auth)
3. **Nitter mirrors** — public mirrors (xcancel.com first, 8 fallbacks) for profile + search
4. **DuckDuckGo site-search → tweet hydration** — last-resort for both profiles and search

This layered approach means the actor stays useful even when individual strategies are degraded (Nitter mirrors come and go, X rate-limits unauthenticated traffic, DDG occasionally throttles automation).

### Why use this Twitter / X Scraper?

- **No API key needed** — works on the public surface
- **Optional API v2 boost** — drop in your `TWITTER_BEARER_TOKEN` for best results
- **Multi-strategy resilience** — auto-falls-back when one path is blocked
- **Profile, search, AND URL modes** in one actor
- **Reply / retweet filters** — clean original-content streams
- **Bulk-friendly** — scrape multiple users / queries in a single run

### Use cases

- **Brand monitoring** — track every @mention of your brand
- **Sentiment analysis** — bulk-scrape tweets for AI/ML pipelines
- **Influencer discovery** — find creators in your niche by topic search
- **Crisis communications** — monitor breaking news and trending topics
- **Lead generation** — find people tweeting about a problem you solve
- **Competitor analysis** — track competitor accounts and engagement
- **Research / journalism** — capture viral content and public statements
- **Trend tracking** — surface topics gaining traction

### Input

Profile mode:
```json
{
    "usernames": ["elonmusk", "apify"],
    "maxTweets": 50,
    "includeReplies": false,
    "includeRetweets": true
}
````

Search mode:

```json
{
    "queries": ["AI agents", "hiring frontend"],
    "maxTweets": 100
}
```

URL mode:

```json
{
    "urls": [
        "https://x.com/elonmusk",
        "https://x.com/elonmusk/status/1234567890",
        "https://x.com/search?q=apify"
    ]
}
```

### Output

Each tweet record:

```json
{
    "type": "tweet",
    "id": "1234567890",
    "text": "Tweet body text up to 1000 chars",
    "author": "elonmusk",
    "author_name": "Elon Musk",
    "url": "https://x.com/elonmusk/status/1234567890",
    "created_at": "Mon Jan 15 00:00:00 +0000 2024",
    "replies": 8500,
    "retweets": 12000,
    "likes": 145000,
    "views": 3500000,
    "image_url": "https://pbs.twimg.com/media/…",
    "is_reply": false,
    "is_retweet": false,
    "source": "syndication"
}
```

The `source` field identifies which strategy returned the tweet (`api_v2`, `syndication`, `nitter`, `syndication-tweet`).

### Optional: bring your own API key

If you have a Twitter API v2 bearer token, set it as the env var **`TWITTER_BEARER_TOKEN`** in the actor's "Environment variables" section (or add it as a secret). The actor will automatically prefer the API path when present — significantly improving reliability for search queries.

### How it works

The actor implements four parallel strategies behind a single interface:

- **API v2** uses `api.x.com/2/tweets/search/recent` and `users/by/username` with proper expansion of attached users / media
- **Syndication** parses `__NEXT_DATA__` JSON from `syndication.twitter.com/srv/timeline-profile/screen-name/...`
- **Nitter** scrapes timeline HTML from a list of public Nitter mirrors with anti-bot detection (Anubis, Cloudflare JS challenges)
- **DDG hydration** does a `site:x.com inurl:status` search on DuckDuckGo, extracts tweet IDs, and resolves them via `cdn.syndication.twimg.com/tweet-result` (the same endpoint embed widgets use)

### Cost & speed

- Profile mode: 5–15 seconds per user (depends on which strategy succeeds first)
- Search mode without API key: 10–30 seconds per query
- With `TWITTER_BEARER_TOKEN`: ~3 seconds per target

Memory stays under 256 MB. No browser required.

### Related actors

- **Reddit Scraper** — bulk Reddit post / comment / community scraping
- **TikTok Scraper** — TikTok profiles, hashtags, search
- **LinkedIn Profile Scraper** — bulk LinkedIn profile data + email finder
- **Email Verifier** — verify scraped emails for outreach hygiene

### FAQ

**Q: Why does search sometimes return 0 tweets?**
Twitter has heavily restricted unauthenticated search since 2024. Without a bearer token, the actor falls back to Nitter / DDG which catch most public tweets but not all. **For reliable search, set `TWITTER_BEARER_TOKEN`**.

**Q: Why does profile mode return more results than search?**
Profile timelines are served by the syndication endpoint without auth. Search without auth is rate-limited at the X / Nitter layer.

**Q: How do I get a Twitter Bearer Token?**
Sign up at [developer.x.com](https://developer.x.com), create a project, and grab the Bearer Token from the keys/tokens screen. The free tier is enough for most personal projects.

**Q: Is scraping Twitter legal?**
Public tweets are public. The 2022 *Meta v. BrandTotal* case affirmed that scraping public social media data does not violate the CFAA in the US. Always comply with X's Terms of Service when storing data, especially for commercial use.

**Q: Why do some tweets have `views` as null?**
Older Nitter pages don't surface impression counts. The API v2 and syndication paths populate this when available.

# Actor input Schema

## `queries` (type: `array`):

Free-form search queries to find tweets matching keywords. Search via API v2 (if TWITTER\_BEARER\_TOKEN is set) → Nitter mirrors → DuckDuckGo.

## `usernames` (type: `array`):

Twitter / X usernames (without @) to scrape profile timelines for.

## `urls` (type: `array`):

Direct X / Twitter URLs - status URLs, profile URLs, or search URLs.

## `maxTweets` (type: `integer`):

Maximum number of tweets to return per target.

## `includeReplies` (type: `boolean`):

Include reply tweets in profile timelines.

## `includeRetweets` (type: `boolean`):

Include retweets/reposts in profile timelines.

## Actor input object example

```json
{
  "queries": [],
  "usernames": [
    "elonmusk"
  ],
  "urls": [],
  "maxTweets": 25,
  "includeReplies": false,
  "includeRetweets": true
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "queries": [],
    "usernames": [
        "elonmusk"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("convertfleetdotonline/twitter-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "queries": [],
    "usernames": ["elonmusk"],
}

# Run the Actor and wait for it to finish
run = client.actor("convertfleetdotonline/twitter-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "queries": [],
  "usernames": [
    "elonmusk"
  ]
}' |
apify call convertfleetdotonline/twitter-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=convertfleetdotonline/twitter-scraper",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Twitter / X Scraper - Profiles, Tweets, Search & Data Export",
        "description": "Scrape Twitter / X profiles, tweets, hashtags, and search results at scale. Extract follower counts, engagement metrics, user bios, and full tweet history. Supports multi-strategy data collection via Apify API.",
        "version": "0.1",
        "x-build-id": "xVhkkjffyZ0fFbYrU"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/convertfleetdotonline~twitter-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-convertfleetdotonline-twitter-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/convertfleetdotonline~twitter-scraper/runs": {
            "post": {
                "operationId": "runs-sync-convertfleetdotonline-twitter-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/convertfleetdotonline~twitter-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-convertfleetdotonline-twitter-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "properties": {
                    "queries": {
                        "title": "Search queries",
                        "type": "array",
                        "description": "Free-form search queries to find tweets matching keywords. Search via API v2 (if TWITTER_BEARER_TOKEN is set) → Nitter mirrors → DuckDuckGo.",
                        "default": [],
                        "items": {
                            "type": "string"
                        }
                    },
                    "usernames": {
                        "title": "Usernames",
                        "type": "array",
                        "description": "Twitter / X usernames (without @) to scrape profile timelines for.",
                        "default": [],
                        "items": {
                            "type": "string"
                        }
                    },
                    "urls": {
                        "title": "Direct URLs",
                        "type": "array",
                        "description": "Direct X / Twitter URLs - status URLs, profile URLs, or search URLs.",
                        "default": [],
                        "items": {
                            "type": "string"
                        }
                    },
                    "maxTweets": {
                        "title": "Max tweets",
                        "minimum": 1,
                        "maximum": 200,
                        "type": "integer",
                        "description": "Maximum number of tweets to return per target.",
                        "default": 25
                    },
                    "includeReplies": {
                        "title": "Include replies",
                        "type": "boolean",
                        "description": "Include reply tweets in profile timelines.",
                        "default": false
                    },
                    "includeRetweets": {
                        "title": "Include retweets",
                        "type": "boolean",
                        "description": "Include retweets/reposts in profile timelines.",
                        "default": true
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
