# X (Twitter) Media Scraper & Downloader (`khadinakbar/x-media-scraper`) Actor

Download photos, videos, and GIFs from X (Twitter) tweets and profiles. No login required. Provider-backed (ScrapeCreators + SociaVault). MCP-ready.

- **URL**: https://apify.com/khadinakbar/x-media-scraper.md
- **Developed by:** [Khadin Akbar](https://apify.com/khadinakbar) (community)
- **Categories:** Social media, Automation, Lead generation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $5.00 / 1,000 media item founds

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#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

## X (Twitter) Media Scraper & Downloader

**Download photos, videos, and GIFs from X (Twitter) tweets and profiles — no login, no cookies, no browser.**

Extract every photo, native video, and animated GIF from individual tweet URLs or bulk-scrape a profile's recent media timeline. Provider-backed via ScrapeCreators + SociaVault for high reliability. MCP-ready for AI-agent workflows.

***

### What You Get

| Field | Description | Example |
|---|---|---|
| `tweetUrl` | Full tweet URL | `https://x.com/NASA/status/1895...` |
| `tweetId` | Tweet ID string | `"1895937985895723209"` |
| `author` | Display name | `"NASA"` |
| `authorHandle` | @handle | `"NASA"` |
| `tweetText` | Full tweet text | `"Mars rover captures..."` |
| `tweetDate` | Posting date | `"Mon Aug 19 12:00:00 +0000 2026"` |
| `likeCount` | Total likes | `42381` |
| `retweetCount` | Retweets | `5219` |
| `replyCount` | Replies | `873` |
| `viewCount` | View count | `1200000` |
| `mediaType` | `photo`, `video`, or `animated_gif` | `"video"` |
| `mediaUrl` | Direct download URL | `https://video.twimg.com/...mp4` |
| `thumbnailUrl` | Thumbnail/cover image URL | `https://pbs.twimg.com/...jpg` |
| `durationMs` | Video duration in milliseconds | `31533` |
| `width` | Media width px | `1280` |
| `height` | Media height px | `720` |
| `bitrate` | Video bitrate (highest-quality variant selected) | `2176000` |
| `mediaIndex` | Media position within the tweet (0-based) | `0` |
| `kvKey` | Key-value store key when `saveToKeyValueStore=true` | `"1895_0.mp4"` |

***

### Use Cases

- **Content archiving** — back up a creator's entire photo/video library
- **Brand monitoring** — collect all media from competitor accounts
- **Research** — build annotated media datasets from public tweets
- **Journalism** — archive source media from news events before deletion
- **AI training** — gather labeled image/video datasets from topic accounts

***

### How to Use

#### Single tweet — grab all media

```json
{
  "tweetUrls": ["https://x.com/NASA/status/1895937985895723209"]
}
```

#### Bulk profile media

```json
{
  "handles": ["NASA", "SpaceX"],
  "maxTweetsPerHandle": 50,
  "mediaTypes": ["photo", "video"]
}
```

#### Download files to storage

```json
{
  "tweetUrls": ["https://x.com/NASA/status/1895937985895723209"],
  "saveToKeyValueStore": true
}
```

***

### Pricing

Pay per event — you only pay for results.

| Event | Price |
|---|---|
| Actor start | $0.00005 |
| Per media item found | $0.005 |

Typical cost: 100 media items = **$0.50**. A profile with 50 tweet-media posts containing 2–3 images each ≈ 100–150 items ≈ $0.50–$0.75.

***

### API Example

```bash
curl -X POST https://api.apify.com/v2/acts/khadinakbar~x-media-scraper/runs \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $APIFY_TOKEN" \
  -d '{"tweetUrls":["https://x.com/NASA/status/1895937985895723209"]}'
```

***

### Technical Notes

- **Provider-backed**: ScrapeCreators primary → SociaVault fallback. No X login or cookies needed.
- **Best-quality video**: automatically selects the highest-bitrate MP4 variant.
- **Photo format**: returns `?format=jpg&name=large` (original resolution) with `name=thumb` for previews.
- **GIFs**: animated\_gif type returns the looping MP4 used by X internally.
- **No liker/follower data**: only media from tweet content; follower lists and like identities are not scraped.

***

### Legal Disclaimer

This tool accesses publicly available X (Twitter) data. Use in compliance with X's Terms of Service and applicable laws. Do not use for harassment, copyright infringement, or surveillance purposes. The actor operator is not responsible for how scraped data is used.

***

### Related Actors

- [X Tweet Scraper](https://apify.com/khadinakbar/x-tweet-scraper) — full tweet metadata, search, hashtags
- [Twitter Profile & Followers Scraper](https://apify.com/khadinakbar/twitter-profile-followers-scraper) — follower lists and profile data
- [Instagram Post Engagers Scraper](https://apify.com/khadinakbar/instagram-post-engagers-scraper) — Instagram media + engagers

# Actor input Schema

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

One or more tweet URLs to extract media from (e.g. https://x.com/NASA/status/1234567890). Each URL is fetched and all photos/videos/GIFs in the tweet are returned.

## `handles` (type: `array`):

X usernames or handles (with or without @) to bulk-scrape recent media from. Every media tweet in the profile's recent timeline is returned up to maxTweetsPerHandle.

## `maxTweetsPerHandle` (type: `integer`):

Maximum number of tweets to scan per handle when using the handles input. Scans up to this many recent tweets for media.

## `mediaTypes` (type: `array`):

Which media types to extract. photo = static image, video = native X video, animated\_gif = GIF. All three are included by default.

## `saveToKeyValueStore` (type: `boolean`):

When true, each media file is downloaded and saved in the named key-value store 'media'. The dataset row includes a kvKey field with the storage key. Useful for archiving. Increases run time and Apify storage costs.

## Actor input object example

```json
{
  "handles": [
    "NASA"
  ],
  "maxTweetsPerHandle": 15,
  "mediaTypes": [
    "photo",
    "video",
    "animated_gif"
  ],
  "saveToKeyValueStore": false
}
```

# Actor output Schema

## `datasetItems` (type: `string`):

No description

## `outputSummary` (type: `string`):

No description

## `runSummary` (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 = {
    "handles": [
        "NASA"
    ]
};

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

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

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,khadinakbar/x-media-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/Dq5gW8QUJV9XNaZoo/builds/yvDftOdI9GX2Feknu/openapi.json
