# Twitter/X Scraper: Tweets, Profiles & Search (`automation-lab/twitter-scraper`) Actor

Twitter scraper and X scraper for profiles, tweets, timelines, search, followers, and following. Profiles/timelines work without login; search supports advanced syntax.

- **URL**: https://apify.com/automation-lab/twitter-scraper.md
- **Developed by:** [Stas Persiianenko](https://apify.com/automation-lab) (community)
- **Categories:** Social media, Lead generation
- **Stats:** 1,260 total users, 146 monthly users, 93.8% runs succeeded, 9 bookmarks
- **User rating**: 5.00 out of 5 stars

## Pricing

from $1.95 / 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.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — 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: Tweets, Profiles & Search

Use this Twitter scraper / X scraper to collect profiles, tweets, user timelines, follower lists, following lists, and search results in structured JSON. Profiles and user timelines work without a login, search supports advanced X/Twitter query syntax, and direct HTTP requests keep runs lightweight compared with browser-based tweet scrapers.

### Why choose this X and tweet scraper?

| Need | What this actor gives you |
|------|---------------------------|
| One scraper for common Twitter/X jobs | Profiles, tweet URLs, user timelines, search, followers, and following in one actor |
| Start without account setup | Profiles and user timelines run with guest authentication — no cookies required |
| Advanced tweet discovery | Search accepts X/Twitter syntax such as `from:user`, `since:YYYY-MM-DD`, `min_faves:N`, `filter:media`, and `lang:en` |
| Clear auth expectations | Search, followers, and following require your Twitter cookies; tweets by URL may need cookies for restricted tweets |
| Lower runtime overhead | Direct HTTP implementation at 256 MB memory; no browser session is started for every page |

### What does Twitter/X Scraper do?

This actor extracts public data from Twitter/X:

- **Profiles** — follower counts, bio, join date, verification status, and more, without login
- **User timelines** — latest available tweets from any user's timeline with pagination, without login
- **Tweets by URL** — full tweet data from specific URLs including likes, retweets, media
- **Search** — find tweets by keyword, hashtag, or advanced query with full Twitter search syntax
- **Followers** — extract a user's follower list with profile details when cookies are provided
- **Following** — extract who a user follows with full profile data when cookies are provided

### Use this with a brand monitoring stack

Twitter/X is one layer of a complete brand-monitoring workflow on Apify. Pair Twitter/X Scraper with:

- [Reddit Scraper](https://apify.com/automation-lab/reddit-scraper) for community discussions, product feedback, and crisis signals
- [Threads Scraper](https://apify.com/automation-lab/threads-scraper) for public Threads posts and keyword searches
- [G2 Reviews & Products Scraper](https://apify.com/automation-lab/g2-scraper) for B2B review intelligence and competitor sentiment
- [Trustpilot Scraper](https://apify.com/automation-lab/trustpilot-scraper) for consumer review monitoring
- [Google News Scraper](https://apify.com/automation-lab/google-news-scraper) for media coverage and PR alerts
- [Website Change Monitor](https://apify.com/automation-lab/website-change-monitor) for competitor pricing, changelog, and landing-page changes

Together these actors form a custom brand-monitoring pipeline on Apify: social conversations, review sites, news coverage, and owned-web changes in one workflow.

### What works without login?

| Mode | Cookies needed? | Notes |
|------|----------------|-------|
| Profiles | No | Guest authentication, ~2 sec per profile |
| User timelines | No | Guest auth returns popular tweets (not chronological) |
| Tweets by URL | Recommended | Works without cookies for some tweets, but many require auth |
| Search | Yes | Twitter requires login for search — no way around it |
| Followers | Yes | Requires cookies — Twitter locks down follower lists |
| Following | Yes | Requires cookies — same as followers |

**Why do some modes need cookies?** Twitter has progressively locked down their API. Profiles and timelines still work with guest tokens, but individual tweet lookup and search require authenticated sessions. Competitors either require cookies too (they just don't always tell you upfront) or use browser automation which costs 5-10x more per result. We use direct HTTP requests — no browser overhead — which keeps costs low.

Getting cookies takes 30 seconds: open x.com in your browser, grab two values from DevTools, paste them in. Instructions below.

### Why use this scraper?

- **Tiered pay-per-event pricing** — starts at $0.003 per tweet on the FREE tier and discounts with paid Apify plans
- **No API keys needed** — profiles and timelines work without any login
- **No browser overhead** — pure HTTP at 256 MB memory, fast and cheap
- **Self-healing endpoints** — dynamically resolves GraphQL endpoint IDs from X's frontend JS, survives API rotations automatically
- **Rich data** — likes, retweets, replies, views, bookmarks, quotes, media URLs, hashtags, mentions
- **Full search syntax** — from:user, since:date, min\_faves:N, filter:media, lang:code, and more

### Who is it for?

#### Marketing and PR teams

- **Social media monitoring** — track brand mentions, competitor activity, or industry trends in real time
- **Campaign analysis** — measure tweet performance, hashtag reach, and engagement during campaigns
- **Crisis monitoring** — detect negative sentiment spikes and respond quickly

#### Sales and growth teams

- **Lead generation** — find potential customers through profile analysis and relevant conversations
- **Audience research** — understand what your target market talks about and who they follow

#### Research and analysis

- **Academic research** — collect tweets on specific topics for sentiment analysis, NLP, or social network studies
- **Content analysis** — study viral tweets, media usage, and hashtag trends
- **Influencer research** — analyze follower counts, engagement rates, and posting patterns

#### Developers and data teams

- **Archiving** — save specific tweets by URL for permanent record
- **Dataset building** — create structured Twitter datasets for ML training or analytics dashboards

### How much does it cost to scrape Twitter/X?

Pay-per-event pricing. You only pay for results you get.

For large runs, set **Maximum charge per run** in Apify before execution (especially with broad queries or `maxResults: 0`/very high values). This actor now checks the charge limit and exits when the PPE cap is reached.

| Event | Price | Notes |
|-------|-------|-------|
| Actor start | $0.005 FREE / $0.00475 BRONZE | One-time per run |
| Tweet scraped | $0.003 FREE / $0.0027 BRONZE | Per tweet (all modes) |
| Profile scraped | $0.003 FREE / $0.0027 BRONZE | Per profile |
| Follower/following scraped | $0.00115 FREE / $0.001 BRONZE | Per user in follower/following lists |

**Cost examples:**

| Task | Cost | Comparison |
|------|------|------------|
| 10 profiles | ~$0.035 | FREE tier |
| 100 tweets (user timeline) | ~$0.31 | FREE tier |
| 1,000 tweets (search) | ~$3.01 | FREE tier |
| 10,000 tweets | ~$30.01 | FREE tier |

The Apify free tier ($5/month) gets you roughly 1,600 tweets or 1,600 profiles per month before discounts or run-start charges.

### How to scrape Twitter/X

1. Open [Twitter/X Scraper](https://apify.com/automation-lab/twitter-scraper) in Apify Console
2. Pick a mode: Profiles, User timeline, Tweets by URL, or Search
3. Enter usernames, tweet URLs, or search queries
4. For search or tweets-by-URL: paste your Twitter cookies (see below)
5. Click **Start** and download results as JSON, CSV, or Excel

### How to get Twitter cookies

Required for search mode, recommended for tweets-by-URL.

1. Log in to [x.com](https://x.com) in your browser
2. Open DevTools (F12) → **Application** tab → **Cookies** → `https://x.com`
3. Find and copy the values of `auth_token` and `ct0`
4. Paste in the input field as: `auth_token=YOUR_TOKEN; ct0=YOUR_CT0`

Cookies typically last several weeks before you need to refresh them.

### What data can I extract from Twitter/X?

#### Tweet fields

| Field | Type | Description |
|-------|------|-------------|
| `text` | string | Full tweet text (including long-form notes) |
| `url` | string | Permanent tweet URL |
| `likeCount` | number | Number of likes |
| `retweetCount` | number | Number of retweets |
| `replyCount` | number | Number of replies |
| `viewCount` | number | Number of views (timeline/search modes) |
| `bookmarkCount` | number | Number of bookmarks |
| `quoteCount` | number | Number of quote tweets |
| `createdAt` | string | Tweet creation date |
| `authorUsername` | string | Author's username |
| `authorFollowers` | number | Author's follower count |
| `hashtags` | array | Hashtags used |
| `mentions` | array | Mentioned users |
| `mediaUrls` | array | Photo and video URLs |
| `mediaType` | string | `photo`, `video`, `gif`, or `null` |
| `isReply` / `isRetweet` / `isQuote` | boolean | Tweet type flags |
| `conversationId` | string | Thread root tweet ID |

#### Profile fields

| Field | Type | Description |
|-------|------|-------------|
| `username` | string | Twitter handle |
| `name` | string | Display name |
| `bio` | string | Profile biography |
| `followers` | number | Follower count |
| `following` | number | Following count |
| `tweetsCount` | number | Total tweets posted |
| `likesCount` | number | Total likes given |
| `isBlueVerified` | boolean | Blue verification status |
| `joinedAt` | string | Account creation date |
| `profilePicture` | string | High-res profile image URL |
| `coverPicture` | string | Banner image URL |
| `website` | string | Website from profile |
| `location` | string | Location from profile |

### How do I scrape tweets and Twitter profiles?

| Parameter | Description | Default |
|-----------|-------------|---------|
| `mode` | `profiles`, `tweets`, `user-tweets`, `search`, `followers`, or `following` | `profiles` |
| `usernames` | Twitter usernames (for profiles and user-tweets modes) | — |
| `tweetUrls` | Tweet URLs or numeric IDs (for tweets mode) | — |
| `searchTerms` | Search queries (for search mode) | — |
| `searchMode` | Sort order for search: `Top` or `Latest` | `Top` |
| `maxResults` | Max results per query/user | 50 |
| `twitterCookie` | Twitter cookies (format: `auth_token=...; ct0=...`) | — |

#### Search operators

Search mode supports Twitter's full advanced search syntax:

| Operator | Example | Description |
|----------|---------|-------------|
| `from:user` | `from:elonmusk` | Tweets from a specific user |
| `to:user` | `to:NASA` | Tweets replying to a user |
| `since:date` | `since:2024-01-01` | Tweets after a date |
| `until:date` | `until:2024-12-31` | Tweets before a date |
| `min_faves:N` | `min_faves:100` | Minimum likes |
| `min_retweets:N` | `min_retweets:50` | Minimum retweets |
| `filter:media` | `web scraping filter:media` | Only tweets with media |
| `filter:images` | `apify filter:images` | Only tweets with images |
| `filter:videos` | `AI filter:videos` | Only tweets with videos |
| `lang:code` | `scraping lang:en` | Filter by language |
| `-filter:replies` | `from:NASA -filter:replies` | Exclude replies |

Combine operators freely: `from:elonmusk since:2024-01-01 min_faves:1000 lang:en`

### Output examples

#### Tweet

```json
{
    "type": "tweet",
    "id": "1519480761749016577",
    "url": "https://x.com/elonmusk/status/1519480761749016577",
    "text": "Next I'm buying Coca-Cola to put the cocaine back in",
    "createdAt": "Thu Apr 28 00:56:58 +0000 2022",
    "likeCount": 4253891,
    "retweetCount": 588370,
    "replyCount": 168937,
    "quoteCount": 167450,
    "bookmarkCount": 21524,
    "authorUsername": "elonmusk",
    "authorName": "Elon Musk",
    "authorFollowers": 236257999,
    "hashtags": [],
    "mentions": [],
    "mediaUrls": []
}
```

#### Profile

```json
{
    "type": "profile",
    "username": "elonmusk",
    "name": "Elon Musk",
    "followers": 236258375,
    "following": 1292,
    "tweetsCount": 98776,
    "likesCount": 215478,
    "isBlueVerified": true,
    "joinedAt": "Tue Jun 02 20:12:29 +0000 2009",
    "profilePicture": "https://pbs.twimg.com/profile_images/..._400x400.jpg"
}
```

#### Follower/Following

```json
{
    "type": "follower",
    "id": "44196397",
    "username": "elonmusk",
    "url": "https://x.com/elonmusk",
    "name": "Elon Musk",
    "bio": "",
    "location": "",
    "followers": 237387109,
    "following": 1301,
    "tweetsCount": 100007,
    "isVerified": false,
    "isBlueVerified": true,
    "joinedAt": "Tue Jun 02 20:12:29 +0000 2009",
    "profilePicture": "https://pbs.twimg.com/profile_images/..._400x400.jpg",
    "sourceUsername": "NASA",
    "scrapedAt": "2026-03-25T04:30:00.000Z"
}
```

### How do I get the best results from Twitter Scraper?

- **Start small** — test with `maxResults: 10` before scaling up
- **User timeline order** — guest auth returns popular tweets, not chronological. Use search mode with `from:username` + cookies for chronological order
- **Endpoint auto-resolution** — the actor extracts GraphQL endpoint IDs from X's frontend JS on each run, so it survives API rotations
- **Rate limits** — Twitter throttles requests; the actor adds delays automatically, so large runs may take longer
- **Combine modes** — use Search to discover relevant accounts, then User Timeline to collect available timeline posts from specific users
- **Use advanced search operators** — narrow results with `min_faves:100`, `filter:media`, or `lang:en` to get higher-signal data and reduce costs
- **Schedule recurring runs** — set up daily or weekly scrapes in Apify Console to monitor accounts or keywords over time automatically

### How to scrape Twitter without getting blocked

Twitter actively limits access to its data — here's how this scraper stays reliable:

- **Direct HTTP, not browser automation** — the actor sends raw HTTP requests, mimicking what the X frontend does. This avoids browser fingerprinting and keeps memory usage at 256 MB instead of 1-2 GB.
- **Self-healing GraphQL endpoints** — Twitter periodically rotates its internal GraphQL endpoint IDs. This scraper re-extracts those IDs from X's frontend JavaScript on every run, so it automatically adapts without manual updates.
- **Guest token authentication** — profiles and user timelines use guest tokens (no login required), which are less aggressively rate-limited than API keys.
- **Bounded transient-failure recovery** — rate limits, temporary 5xx responses, socket resets, timeouts, and TLS disconnects are retried up to three times with exponential backoff and jitter. Authentication, validation, and not-found failures still return immediately.
- **Authenticated sessions for search** — search requires valid browser cookies (`auth_token` + `ct0`). Cookies last several weeks. If you get auth errors, refresh them from x.com in under a minute.

For large-scale runs (10K+ tweets), spread queries across multiple runs and use the `since:` / `until:` operators to batch by date range.

### Twitter data export: how to download tweets

Once a run completes, you can download your scraped tweets in multiple formats:

- **JSON** — full structured data, best for developers and data pipelines
- **CSV** — opens directly in Excel or Google Sheets, ideal for analysts
- **Excel (.xlsx)** — pre-formatted spreadsheet, ready to share
- **XML** — compatible with legacy enterprise systems

**Via Apify Console:** Click **Export** on the dataset page and choose your format.

**Via API:** Use the dataset export endpoint:

```bash
curl "https://api.apify.com/v2/datasets/DATASET_ID/items?format=csv&token=YOUR_TOKEN" \
  --output tweets.csv
```

**Automatic export integrations:** Connect the scraper to Google Sheets, Airtable, or a webhook endpoint so data is exported automatically after each run — no manual downloads needed.

### API usage

#### Node.js

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

const client = new ApifyClient({ token: 'YOUR_API_TOKEN' });
const run = await client.actor('automation-lab/twitter-scraper').call({
    mode: 'profiles',
    usernames: ['elonmusk', 'OpenAI'],
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(items);
```

#### Python

```python
from apify_client import ApifyClient

client = ApifyClient("YOUR_API_TOKEN")
run = client.actor("automation-lab/twitter-scraper").call(run_input={
    "mode": "user-tweets",
    "usernames": ["NASA"],
    "maxResults": 50,
})
items = client.dataset(run["defaultDatasetId"]).list_items().items
print(items)
```

#### cURL

```bash
curl "https://api.apify.com/v2/acts/automation-lab~twitter-scraper/runs" \
  -X POST \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"mode": "profiles", "usernames": ["elonmusk"]}'
```

### Integrations

Connect Twitter/X Scraper to your workflow using [Apify integrations](https://apify.com/integrations):

- **Google Sheets** — export tweets and profiles to a spreadsheet automatically. Useful for tracking follower growth or building engagement reports
- **Slack / Discord** — get notifications when scraping finishes or when tweets match specific criteria
- **Zapier / Make** — automate workflows triggered by scraping results, e.g., save viral tweets to Airtable or trigger alerts for brand mentions
- **Webhooks** — send data to your API endpoint automatically for custom processing
- **Scheduled runs** — set up recurring scrapes (hourly, daily, weekly) to monitor accounts or search queries over time
- **Data warehouses** — pipe results to BigQuery, Snowflake, or PostgreSQL for large-scale analytics
- **AI/LLM pipelines** — feed tweets into sentiment analysis, topic classification, or trend detection models

### Use with AI agents via MCP

Twitter/X Scraper is available as a tool for AI assistants that support the [Model Context Protocol (MCP)](https://docs.apify.com/platform/integrations/mcp). This lets you use natural language to scrape data — just ask your AI assistant and it will configure and run the scraper for you.

#### Setup for Claude Code

```bash
claude mcp add --transport http apify "https://mcp.apify.com/?tools=automation-lab/twitter-scraper"
```

#### Setup for Claude Desktop, Cursor, or VS Code

Add this to your MCP config file:

```json
{
    "mcpServers": {
        "apify": {
            "url": "https://mcp.apify.com/?tools=automation-lab/twitter-scraper"
        }
    }
}
```

Your AI assistant will use OAuth to authenticate with your Apify account on first use.

#### Example prompts

Once connected, try asking your AI assistant:

- "Get the latest 200 tweets from @elonmusk"
- "Search Twitter for tweets about 'climate change' from the past week"
- "Get the first 500 followers of @NASA with their profile details"

Learn more in the [Apify MCP documentation](https://docs.apify.com/platform/integrations/mcp).

### Legality

This actor scrapes publicly available data from Twitter/X. It does not access private accounts, direct messages, or any data behind login walls.

Web scraping of public data is generally legal in most jurisdictions. Always respect Twitter's Terms of Service and applicable data protection laws (GDPR, CCPA) when using scraped data.

### FAQ

**Does this need a Twitter API key?**
No. Profiles and user timelines use guest authentication. Search and tweets-by-URL use your browser cookies (not API keys).

**Why do some modes need cookies?**
Twitter has locked down their API over the past year. Guest tokens still work for profiles and timelines, but search and individual tweet lookup require authenticated sessions. This is a Twitter limitation, not ours. We use direct HTTP (no browser) to keep costs low and reliable.

**Can I scrape private accounts?**
No. Only publicly available data.

**How many tweets can I scrape?**
Up to 5,000 per user in user-tweets mode. Search mode supports pagination up to 5,000 results per query.

**What if Twitter rotates their API?**
The actor dynamically extracts endpoint IDs from X's frontend JavaScript on each run. It automatically adapts to API changes.

**Why are some tweets-by-URL empty?**
Some tweets return empty data even with valid cookies. This happens with restricted, age-gated, or visibility-limited tweets. This is a Twitter API limitation.

**Can I scrape a user's follower list?**
Yes. Use `followers` or `following` mode with the target username. Set `maxResults` to control how many to extract. Both modes require cookies. Large accounts (1M+ followers) may take longer due to Twitter throttling, and availability depends on your authenticated session.

**How long do cookies last?**
Typically several weeks. If you get authentication errors, refresh your cookies from x.com.

**The scraper returns 0 results for user-tweets mode — what's wrong?**
Guest authentication for user-tweets mode returns popular tweets, not all tweets. If the user hasn't posted recently popular content, the result set may be small. Try search mode with `from:username` and cookies for more comprehensive results.

**I'm getting "Could not authenticate" errors — how do I fix this?**
Your cookies have likely expired. Log in to x.com in your browser again, open DevTools (F12) > Application > Cookies > x.com, and copy fresh values for `auth_token` and `ct0`. Paste them in the format: `auth_token=YOUR_TOKEN; ct0=YOUR_CT0`.

### Related scrapers

- [Instagram Scraper](https://apify.com/automation-lab/instagram-scraper) — Scrape Instagram posts, profiles, comments, and hashtags
- [Threads Scraper](https://apify.com/automation-lab/threads-scraper) — Extract posts and profiles from Meta's Threads
- [TikTok Scraper](https://apify.com/automation-lab/tiktok-scraper) — Scrape TikTok videos, profiles, and trending hashtag feeds
- [Reddit Scraper](https://apify.com/automation-lab/reddit-scraper) — Scrape posts, comments, and communities from Reddit
- [Bluesky Scraper](https://apify.com/automation-lab/bluesky-scraper) — Scrape Bluesky posts, profiles, and search results
- [Pinterest Scraper](https://apify.com/automation-lab/pinterest-scraper) — Scrape Pinterest pins, boards, and profile data

### Use with AI agents via x402 (no Apify account)

Agent workflows can run this actor through Apify MCP without an Apify account when the MCP client uses a funded x402 wallet. Use the actor-specific MCP endpoint:

`https://mcp.apify.com?tools=automation-lab/twitter-scraper&payment=x402`

This keeps existing Apify MCP/API usage unchanged; x402 only changes payment/authentication for clients that support it. Learn more in Apify's [x402 integration docs](https://docs.apify.com/platform/integrations/x402).

# Actor input Schema

## `mode` (type: `string`):

Select what to scrape from Twitter/X.

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

Enter Twitter/X usernames for profile, user-tweets, followers, or following modes. @ is optional; examples: elonmusk or @elonmusk.

## `tweetUrls` (type: `array`):

Enter tweet URLs (https://x.com/user/status/123 or https://twitter.com/user/status/123) or numeric tweet IDs.

## `searchTerms` (type: `array`):

Enter search terms or Twitter advanced search queries. Supports operators like from:user, since:2024-01-01, min\_faves:100, filter:media, lang:en.

## `searchMode` (type: `string`):

Sort search results by relevance (Top) or chronologically (Latest).

## `maxResults` (type: `integer`):

Maximum number of results to return per query/username in user-tweets, search, followers, and following modes.

## `twitterCookie` (type: `string`):

Required for search, followers, and following modes; recommended for tweets-by-URL. Paste cookies in this format: auth\_token=YOUR\_TOKEN; ct0=YOUR\_CT0. Get them from browser DevTools → Application → Cookies → x.com.

## Actor input object example

```json
{
  "mode": "profiles",
  "usernames": [
    "elonmusk"
  ],
  "tweetUrls": [
    "https://x.com/elonmusk/status/1893749736647471554"
  ],
  "searchTerms": [
    "apify web scraping"
  ],
  "searchMode": "Top",
  "maxResults": 10,
  "twitterCookie": "auth_token=YOUR_AUTH_TOKEN; ct0=YOUR_CT0"
}
```

# Actor output Schema

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

Scraped Twitter/X records in the overview dataset view.

# 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 = {
    "mode": "profiles",
    "usernames": [
        "elonmusk"
    ],
    "tweetUrls": [
        "https://x.com/elonmusk/status/1893749736647471554"
    ],
    "searchTerms": [
        "apify web scraping"
    ],
    "maxResults": 10,
    "twitterCookie": "auth_token=YOUR_AUTH_TOKEN; ct0=YOUR_CT0"
};

// Run the Actor and wait for it to finish
const run = await client.actor("automation-lab/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 = {
    "mode": "profiles",
    "usernames": ["elonmusk"],
    "tweetUrls": ["https://x.com/elonmusk/status/1893749736647471554"],
    "searchTerms": ["apify web scraping"],
    "maxResults": 10,
    "twitterCookie": "auth_token=YOUR_AUTH_TOKEN; ct0=YOUR_CT0",
}

# Run the Actor and wait for it to finish
run = client.actor("automation-lab/twitter-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 '{
  "mode": "profiles",
  "usernames": [
    "elonmusk"
  ],
  "tweetUrls": [
    "https://x.com/elonmusk/status/1893749736647471554"
  ],
  "searchTerms": [
    "apify web scraping"
  ],
  "maxResults": 10,
  "twitterCookie": "auth_token=YOUR_AUTH_TOKEN; ct0=YOUR_CT0"
}' |
apify call automation-lab/twitter-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,automation-lab/twitter-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/tIpjRQruPOB39HLf5/builds/4aauuOyjd1Rv6sxT4/openapi.json
