# X / Twitter Ultimate Scraper (`khnaami/x-twitter-ultimate-scraper`) Actor

The most comprehensive, reliable, and stealthy X (Twitter) Intelligence & Data Scraper on Apify.
Built with JavaScript (Node.js), Crawlee, and Playwright, featuring automatic URL routing, login modal dismissal, and 12 specialized extraction modules.

- **URL**: https://apify.com/khnaami/x-twitter-ultimate-scraper.md
- **Developed by:** [khalid naami](https://apify.com/khnaami) (community)
- **Features:** Limited permissions
- **Stats:** 3 total users, 2 monthly users, 96.7% runs succeeded, 1 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

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

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
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.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## 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.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## X / Twitter Ultimate All-in-One Scraper (Enterprise Edition)

The most comprehensive, reliable, and stealthy **X (Twitter) Intelligence & Data Scraper** on Apify.\
Built with **JavaScript (Node.js), Crawlee, and Playwright**, featuring automatic URL routing, login modal dismissal, and 12 specialized extraction modules.

***

### 🌟 12 Scraping Modules Supported

1. **User Profiles & B2B Leads**: Official display name, @handle, verified checkmark status, followers count, following count, total tweets, bio, location, join date, and **direct contact email and phone number extraction**.
2. **User Tweets & Timelines**: Full tweet text (including long-form articles), publication timestamps, direct tweet permalinks, views/impressions, likes, retweets, replies, and quotes.
3. **Tweet Replies & Thread Reconstruction**: Scrapes complete conversation threads and user replies.
4. **Advanced Keyword Search**: Queries X search with live filters, date windows, and engagement thresholds (`min_faves:500`).
5. **High-Res Photos, Videos & Media**: Direct MP4 video download URLs, thumbnails, and original photo URLs.
6. **Hashtags & Trending Topics**: Worldwide and local trending topics with tweet volumes.
7. **Followers & Following Networks**: User social graph connections.
8. **User Likes Timeline**: Tweets favorited by target accounts.
9. **X Lists**: Curated lists and member feeds.
10. **X Communities**: Community topics and discussions.
11. **X Spaces**: Audio live stream metadata, hosts, and listener stats.
12. **Screen Name ⇄ Rest ID Converter**: Converts `@handles` to immutable numeric Twitter IDs and vice versa.

***

### 📥 Input Configuration

| Parameter | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| `scrapeMode` | Select | `"AUTO_DETECT"` | Choose from `AUTO_DETECT`, `USER_PROFILES`, `USER_TWEETS`, `TWEET_REPLIES`, `ADVANCED_SEARCH`, `HASHTAGS_TRENDS`, `FOLLOWERS_FOLLOWING`, `USER_LIKES`, `LISTS`, `COMMUNITIES`, `SPACES`, `USER_ID_CONVERTER`. |
| `targetUrls` | Array | Required | Target profile URLs, tweet links, or handles (e.g. `https://x.com/elonmusk`, `@OpenAI`). |
| `searchQueries` | Array | `[]` | Search phrases or queries for X Search mode. |
| `maxTweets` | Integer | `20` | Maximum tweets/items to extract. |
| `maxRepliesPerTweet` | Integer | `10` | Max replies to extract in conversation threads. |
| `extractEmailAndPhone` | Boolean | `true` | Extract business emails and phone numbers from bios. |
| `proxyConfiguration` | Object | `RESIDENTIAL` | Apify Residential Proxy settings. |
| `customCookies` | String | `""` | Optional session cookies (`auth_token`, `ct0`) for authenticated mode. |

***

### 📤 Sample Output (Profile with Leads)

```json
{
  "type": "USER_PROFILE",
  "url": "https://x.com/elonmusk",
  "username": "elonmusk",
  "name": "Elon Musk",
  "biography": "",
  "location": "",
  "followersCount": 210000000,
  "followingCount": 850,
  "isVerified": true,
  "recentTweets": [
    {
      "type": "TWEET",
      "tweetId": "1840000000000000000",
      "tweetUrl": "https://x.com/elonmusk/status/1840000000000000000",
      "text": "Occupying Mars",
      "likesRaw": "250K",
      "retweetsRaw": "35K",
      "viewsRaw": "15M"
    }
  ],
  "scrapedAt": "2026-10-08T10:00:00.000Z"
}
```

***

### 🛡️ Anti-Block & Compliance

- Automatic login modal & bottom sheet dismissal.
- User-Agent emulation and security client headers.
- Uses Residential Proxy rotation by default.

***

### 📄 License

Apache-2.0

# Actor input Schema

## `scrapeMode` (type: `string`):

Select target data mode on X, or choose AUTO_DETECT to automatically identify the URL type.

## `targetUrls` (type: `array`):

User profiles, tweet links, or handles (e.g. https://x.com/elonmusk, @OpenAI, or https://x.com/elonmusk/status/...).

## `searchQueries` (type: `array`):

Keywords or search filters (e.g. 'AI agents', 'crypto min_faves:500', 'from:elonmusk since:2025-01-01').

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

Maximum number of tweets, replies, or search results to extract.

## `maxRepliesPerTweet` (type: `integer`):

Maximum replies to extract when scraping conversation threads.

## `extractEmailAndPhone` (type: `boolean`):

Automatically parses user bios and locations to extract business emails and phone numbers.

## `proxyConfiguration` (type: `object`):

Apify Proxy settings. Residential proxies are recommended for X (Twitter) to ensure high reliability and zero IP limits.

## `customCookies` (type: `string`):

Optional X cookies (JSON array or 'auth_token=...; ct0=...' format) for scraping protected tweets, full follower lists, or running in authenticated mode.

## Actor input object example

```json
{
  "scrapeMode": "AUTO_DETECT",
  "targetUrls": [
    {
      "url": "https://x.com/elonmusk"
    },
    {
      "url": "https://x.com/OpenAI"
    }
  ],
  "searchQueries": [],
  "maxTweets": 20,
  "maxRepliesPerTweet": 10,
  "extractEmailAndPhone": true,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}
```

# Actor output Schema

## `results` (type: `string`):

Scraped X/Twitter records (Profiles, Tweets, Replies, Search Results, Media, Lists, Trends, Spaces)

## `overview` (type: `string`):

High-level summary report and execution metrics stored in Key-Value store

# 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 = {
    "targetUrls": [
        {
            "url": "https://x.com/elonmusk"
        },
        {
            "url": "https://x.com/OpenAI"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("khnaami/x-twitter-ultimate-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 = { "targetUrls": [
        { "url": "https://x.com/elonmusk" },
        { "url": "https://x.com/OpenAI" },
    ] }

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

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

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

```

## CLI example

```bash
echo '{
  "targetUrls": [
    {
      "url": "https://x.com/elonmusk"
    },
    {
      "url": "https://x.com/OpenAI"
    }
  ]
}' |
apify call khnaami/x-twitter-ultimate-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,khnaami/x-twitter-ultimate-scraper"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/ZXiYC5c1fYS2I7NQP/builds/w3QXuyYBZzv87NmOY/openapi.json
