# X (Twitter) User Posts Scraper (`apt_marble/x-twitter-user-posts-scraper`) Actor

Collect the posts of any X (Twitter) account as clean, structured JSON - full text, likes, reposts, replies, views and timestamps - for one handle or a whole list. Usernames are resolved automatically. Built for brand archiving, competitor tracking and engagement analysis.

- **URL**: https://apify.com/apt_marble/x-twitter-user-posts-scraper.md
- **Developed by:** [Hamza](https://apify.com/apt_marble) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.35 / 1,000 post collecteds

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?

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) User Posts Scraper

Collect the **posts of any X (Twitter) account** as clean, structured JSON - full text, likes, reposts, replies, views and timestamps - for one handle or a whole watchlist. Built for content research, brand monitoring, competitor analysis and archive building.

### Why this scraper

- **Batch by design** - one account or a list; every post lands in one dataset, tagged with its author.
- **Any input format** - @handles, bare usernames, or full x.com / twitter.com profile links all work.
- **Full engagement data** - likes, reposts, replies and view counts on every post.
- **Handles and ids resolved for you** - usernames are resolved to accounts automatically.
- **Automatic pagination** - walks the timeline and removes duplicates.
- **Pay only for what you get** - pay-per-event pricing: one small charge per post delivered.

### What you get

One dataset row per post:

| Field | Description |
|-------|-------------|
| `postId` / `postUrl` | Post id and link |
| `authorUsername` / `authorName` | The author |
| `text` | Full post text |
| `likes` / `reposts` / `replies` / `views` | Engagement counts |
| `createdAt` | When it was posted |
| `mediaCount` / `mediaTypes` | How many photos/videos/GIFs the post has, and which kinds |
| `mediaUrls` | Best direct URL per media item (highest-quality mp4 for videos) |
| `mediaThumbnails` | Thumbnail/poster image per media item |
| `media` | Full media detail: type, dimensions, duration, and every video variant |
| `scrapedAt` | Timestamp of collection |

### Input

| Field | Type | Default | Description |
|-------|------|---------|-------------|
| **Usernames** | list | *(required)* | X usernames or profile links, one per line |
| **Max posts per user** | number | 200 | How many posts to collect per account |

### Ideas

- Archive a brand's posts for compliance or research
- Track what a competitor announces and when
- Analyze which post formats earn the most engagement in your niche
- Feed an account's posts into your own analytics pipeline

### FAQ

**Do I need an X account?**
No. Paste handles or links and run.

**How far back does it go?**
It walks the account's timeline from the most recent posts back, up to the cap you set.

**What formats can I export?**
JSON, CSV, Excel, XML, or straight into your pipeline via the Apify API.

# Actor input Schema

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

Accounts whose posts you want.

## `maxPostsPerUser` (type: `integer`):

Stop after this many posts per account.

## Actor input object example

```json
{
  "usernames": [
    "NASA"
  ],
  "maxPostsPerUser": 20
}
```

# Actor output Schema

## `dataset` (type: `string`):

No description

# 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 = {
    "usernames": [
        "NASA"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("apt_marble/x-twitter-user-posts-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 = { "usernames": ["NASA"] }

# Run the Actor and wait for it to finish
run = client.actor("apt_marble/x-twitter-user-posts-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 '{
  "usernames": [
    "NASA"
  ]
}' |
apify call apt_marble/x-twitter-user-posts-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,apt_marble/x-twitter-user-posts-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/gig2wDwCVP8O3NIHL/builds/Gft8Cx8GO2Qe4LOs0/openapi.json
