# Twitter (X) Comments Scraper (`filexy634/twitter-comments-scraper`) Actor

Scrape the replies (comments) of X/Twitter posts without the official API.

- **URL**: https://apify.com/filexy634/twitter-comments-scraper.md
- **Developed by:** [code gerald](https://apify.com/filexy634) (community)
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $9.00 / 1,000 results

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/actors/running/actors-in-store.md#pay-per-event

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

## Twitter (X) Comments Scraper

Scrapes the replies (comments) of X/Twitter posts without the official API. Give it one or many post URLs; it opens each conversation in a logged-in browser, scrolls it, expands hidden reply sections ("Show more replies", "Show probable spam") and exports every reply as structured JSON.

### How it works

The Actor reads X's own conversation (`TweetDetail`) responses while scrolling, so output is clean structured data rather than scraped HTML. Unrelated "Discover more" tweets are dropped using the conversation id.

### Authentication

X hides replies from anonymous visitors, so a session is required. Resolved in this order:

1. `cookies` input (Cookie-Editor JSON export; needs `auth_token` and `ct0`)
2. `TW_COOKIES` secret env var (JSON array or `name=value; name2=value2`)
3. Session cached from a previous automated login (key-value store `twitter-session`)
4. Automated login with `twUsername` / `twPassword` (+ `twEmail`), or `TW_USERNAME` / `TW_PASSWORD` / `TW_EMAIL` env vars. 2FA must be off. Cookies are more reliable than automated login.

Always use a throwaway account; accounts used for scraping can be restricted.

### Input

`urls`, `startUrls`, `resultsPerCategory` (default 100, max 1000 per post), `scrapeAll`, `includeSourceTweet`, `cookies`, `twUsername`, `twPassword`, `twEmail`, `proxyConfiguration` (residential recommended), `headless`.

### Output

One item per reply, plus one for the source post (`is_source_tweet: true`). Every item carries `metadata.sourceTweetId` and `inputUrl`. A reply whose `in_reply_to_status_id_str` equals the source id is a top-level comment; otherwise it points at its parent reply.

On empty runs the Actor saves `DEBUG_SCREENSHOT` and `DEBUG_HTML` to the key-value store.

### Notes

Scraping may violate X's Terms of Service; collect only public data and respect data-protection law.

# Actor input Schema

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

Post URLs like https://x.com/user/status/123… (twitter.com links work too). De-duplicated by tweet id.

## `startUrls` (type: `array`):

Same as Post URLs, as request-list objects. Merged with Post URLs.

## `category` (type: `string`):

What to scrape for each post. Currently only replies (the comments under the post).

## `resultsPerCategory` (type: `integer`):

Target number of replies per post (max 1000). The source post itself does not count.

## `parseAllResults` (type: `boolean`):

Accepted for backwards compatibility; items are always fully parsed.

## `scrapeAll` (type: `boolean`):

Scroll and expand the conversation until the per-post target is reached. When off, only the initial page load is returned.

## `includeSourceTweet` (type: `boolean`):

Also output one item for the post itself, flagged is_source_tweet: true.

## `cookies` (type: `array`):

Cookies of a logged-in X session (Cookie-Editor / EditThisCookie JSON export). auth_token and ct0 carry the session. Use a throwaway account.

## `twUsername` (type: `string`):

For automated login when no cookies are given. The account must not use 2FA.

## `twPassword` (type: `string`):

For automated login when no cookies are given. The account must not use 2FA.

## `twEmail` (type: `string`):

Answers X's occasional identity check during automated login.

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

Residential proxies are strongly recommended; datacenter IPs are widely blocked by X.

## `headless` (type: `boolean`):

Untick only for local debugging.

## Actor input object example

```json
{
  "urls": [
    "https://x.com/elonmusk/status/1234567890123456789"
  ],
  "category": "replies",
  "resultsPerCategory": 100,
  "parseAllResults": true,
  "scrapeAll": true,
  "includeSourceTweet": true,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  },
  "headless": true
}
```

# Actor output Schema

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

Table view of the scraped replies.

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

Full dataset items, including the source post flagged is_source_tweet.

# 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 = {
    "urls": [
        "https://x.com/elonmusk/status/1234567890123456789"
    ],
    "proxyConfiguration": {
        "useApifyProxy": true,
        "apifyProxyGroups": [
            "RESIDENTIAL"
        ]
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("filexy634/twitter-comments-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 = {
    "urls": ["https://x.com/elonmusk/status/1234567890123456789"],
    "proxyConfiguration": {
        "useApifyProxy": True,
        "apifyProxyGroups": ["RESIDENTIAL"],
    },
}

# Run the Actor and wait for it to finish
run = client.actor("filexy634/twitter-comments-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 '{
  "urls": [
    "https://x.com/elonmusk/status/1234567890123456789"
  ],
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}' |
apify call filexy634/twitter-comments-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,filexy634/twitter-comments-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/cPb2O32d6RKDp0sQ4/builds/yCxMZCjsBI0yLwWzl/openapi.json
