# Post (Tweet) Scrapper - X.com / Twitter (Pay per result) (`builditn0w/x-twitter-scrapper`) Actor

💰 $0.35 per 1000 tweets / custom search query

- **URL**: https://apify.com/builditn0w/x-twitter-scrapper.md
- **Developed by:** [Lars](https://apify.com/builditn0w) (community)
- **Categories:** Social media, Lead generation, AI
- **Security:** Full permissions
- **Stats:** 209 total users, 1 monthly users, 0.0% runs succeeded, 6 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.35 / 1,000 posts

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

## X (Twitter) Search Crawler

This Apify Actor fetches tweets from X (formerly Twitter) based on provided search queries. It uses the X API to search for tweets and returns the data in a structured format.

### Input

The Actor accepts the following input parameters:

| Field | Type | Description |
| ----- | ---- | ----------- |
| `searchQueries` | Array | Array of search queries to fetch tweets from X (e.g., `from:username since:2024-01-01 until:2024-01-31`) |

#### Search Query Syntax

X (Twitter) supports a variety of search operators that you can use to refine your search:

- `from:username` - Tweets from a specific user
- `to:username` - Tweets replying to a specific user
- `since:YYYY-MM-DD` - Tweets after a specific date
- `until:YYYY-MM-DD` - Tweets before a specific date
- `#hashtag` - Tweets containing a specific hashtag
- `url:example.com` - Tweets containing links to a specific domain
- `filter:media` - Tweets containing media (images, videos)
- `filter:links` - Tweets containing links
- `filter:replies` - Tweets that are replies
- `filter:retweets` - Tweets that are retweets
- `min_retweets:n` - Tweets with at least n retweets
- `min_faves:n` - Tweets with at least n likes

You can combine these operators to create more specific searches.

### Search Query Examples

A simple search query example:

```
from:apify since:2024-01-01 until:2024-01-31
```

A search query example with multiple operators:

```
from:apify since:2024-01-01 until:2024-01-31 filter:media
```

### Output

The Actor outputs the tweet data in a structured format, including:

- Tweet ID
- Tweet text
- Tweet URL
- Creation timestamp
- Engagement metrics (likes, retweets, replies, quotes, bookmarks)
- Media attachments (if present)
- Information about whether the tweet is a retweet or quote
- Search query used to find the tweet

#### Output Schema

Each tweet is returned as a JSON object with the following structure:

| Field | Type | Description |
| ----- | ---- | ----------- |
| `url` | String | The full URL to the tweet on X.com |
| `id` | String | The unique identifier of the tweet |
| `text` | String | The full text content of the tweet |
| `retweet_count` | Number | Number of retweets |
| `reply_count` | Number | Number of replies |
| `like_count` | Number | Number of likes |
| `quote_count` | Number | Number of quote tweets |
| `bookmark_count` | Number | Number of bookmarks |
| `created_at` | String | The timestamp when the tweet was created |
| `isretweet` | Boolean | Whether the tweet is a retweet |
| `isquote` | Boolean | Whether the tweet is a quote tweet |
| `media` | Array | Array of media objects attached to the tweet |
| `search_query` | String | The search query used to find this tweet |

For tweets with media, each item in the `media` array has the following structure:

| Field | Type | Description |
| ----- | ---- | ----------- |
| `type` | String | The type of media (e.g., "photo", "video", "animated_gif") |
| `url` | String | The URL to the media file |
| `display_url` | String | The shortened URL displayed in the tweet |
| `expanded_url` | String | The full URL to the media on X.com |

#### Sample Output

Example of a tweet without media:

```json
{
  "url": "https://x.com/username/status/1234567890123456789",
  "id": "1234567890123456789",
  "text": "@another_user This is an example tweet text showing what the output looks like!",
  "retweet_count": 0,
  "reply_count": 1,
  "like_count": 2,
  "quote_count": 0,
  "bookmark_count": 0,
  "created_at": "Sat Dec 28 15:12:37 +0000 2024",
  "isretweet": false,
  "isquote": false,
  "media": [],
  "search_query": "from:username since:2024-11-26 until:2024-12-31"
}
```

Example of a tweet with media:

```json
{
  "url": "https://x.com/username/status/1234567890123456789",
  "id": "1234567890123456789",
  "text": "@another_user This is an example tweet with an image attached!",
  "retweet_count": 0,
  "reply_count": 0,
  "like_count": 1,
  "quote_count": 0,
  "bookmark_count": 0,
  "created_at": "Fri Dec 27 22:49:00 +0000 2024",
  "isretweet": false,
  "isquote": false,
  "media": [
    {
      "type": "photo",
      "url": "https://pbs.twimg.com/media/example_image.jpg",
      "display_url": "pic.x.com/example",
      "expanded_url": "https://x.com/username/status/1234567890123456789/photo/1"
    }
  ],
  "search_query": "from:username since:2024-11-26 until:2024-12-31"
}
```

# Actor input Schema

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

Array of search queries to fetch tweets from X (e.g., 'from:username since:2024-01-01 until:2024-01-31')

## Actor input object example

```json
{
  "searchQueries": [
    "from:apify since:2025-01-01 until:2025-01-02"
  ]
}
```

# 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 = {
    "searchQueries": [
        "from:apify since:2025-01-01 until:2025-01-02"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("builditn0w/x-twitter-scrapper").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 = { "searchQueries": ["from:apify since:2025-01-01 until:2025-01-02"] }

# Run the Actor and wait for it to finish
run = client.actor("builditn0w/x-twitter-scrapper").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 '{
  "searchQueries": [
    "from:apify since:2025-01-01 until:2025-01-02"
  ]
}' |
apify call builditn0w/x-twitter-scrapper --silent --output-dataset

```

## MCP server setup

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

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/ncBt8IIANduOHt5P8/builds/ANKFNazkHMoBYUQS6/openapi.json
