# Twitter X Images Scrapper (`mwitiderrick/twitter-x-images-scrapper`) Actor

The Twitter/X Image & Video Scraper is a powerful tool designed to extract images and videos from Twitter/X based on search queries quickly and efficiently.

- **URL**: https://apify.com/mwitiderrick/twitter-x-images-scrapper.md
- **Developed by:** [Derrick Mwiti](https://apify.com/mwitiderrick) (community)
- **Categories:** Automation, Social media
- **Features:** Full permissions
- **Stats:** 36 total users, 0 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$5.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 Image & Video Scraper Actor

### Overview

The Twitter/X Image & Video Scraper is a powerful tool designed to extract images and videos from Twitter/X based on search queries quickly and efficiently. This actor simplifies retrieving media content from Twitter/X, making it ideal for researchers, content creators, marketers, and developers who need social media content for analysis, curating collections, or research purposes.

This actor supports authenticated search queries, ensuring reliable access even with X.com's authentication requirements.

### Features

- **Fast and Efficient**: Retrieves Twitter/X media (images and videos) in seconds using optimized Selenium automation
- **Accurate Extraction**: Captures media items with full metadata including usernames, descriptions, and source URLs
- **Intelligent Cookie Management**: Automatically validates authentication cookies and warns when they expire
- **Flexible Media Filtering**: Search for images, videos, or both with separate URL filters
- **Metadata Preservation**: Stores username, tweet URL, and description for each downloaded item
- **Video Support**: Extracts video tweet URLs with yt-dlp integration
- **SEO-Friendly**: Export media metadata in JSON format for integration with external systems
- **Cloud-Ready**: Works on local machines and Apify cloud deployments with proper authentication

### Use Cases

- **Content Curation**: Build image or video collections around specific topics
- **Market Research**: Analyze trending visual content in your industry
- **Social Media Analysis**: Study engagement patterns on specific topics
- **Data Collection**: Gather labeled image datasets for machine learning projects
- **Content Repurposing**: Find source material for blogs, reports, or presentations
- **Trend Monitoring**: Track visual trends and viral content in real-time

### Input Parameters

The actor accepts the following input parameters to customize your search.

| Parameter Name | Type | Description | Default Value |
|---|---|---|---|
| `searchQuery` | String | The search term to find on Twitter/X. Example: `dogs`, `nature photography`, `AI innovations` | `nature` |
| `limit` | Number | Maximum number of media items to download. Range: 1-100 | `20` |
| `mediaType` | String | Type of media to search for: `images`, `videos`, or `all` | `all` |
| `downloadImages` | Boolean | Whether to download and store image files | `true` |
| `downloadVideos` | Boolean | Whether to download video tweets (metadata only, not video files) | `false` |
| `includeUsername` | Boolean | Include the username in downloaded filenames | `true` |
| `includeDescription` | Boolean | Include tweet text in metadata | `true` |

### Example Inputs

#### Search for Dog Images

```json
{
  "searchQuery": "dogs",
  "limit": 10,
  "mediaType": "images",
  "downloadImages": true,
  "downloadVideos": false
}
```

#### Search for Alaska Videos

```json
{
  "searchQuery": "alaska",
  "limit": 15,
  "mediaType": "videos",
  "downloadImages": false,
  "downloadVideos": true
}
```

#### Mixed Media Search

```json
{
  "searchQuery": "nature photography",
  "limit": 25,
  "mediaType": "all",
  "downloadImages": true,
  "downloadVideos": true
}
```

### Output

The actor outputs media metadata in JSON format, stored in the Apify dataset.

#### Example Output Structure

##### Image Output

```json
{
  "filename": "photographer_name_sunset_beach_001.jpg",
  "url": "https://pbs.twimg.com/media/abc123.jpg?format=jpg&name=large",
  "type": "image",
  "username": "photographer_name",
  "description": "Beautiful sunset at the beach",
  "search_query": "sunset beach",
  "status": "downloaded",
  "size_bytes": 245620,
  "content_type": "image/jpeg",
  "public_url": "https://api.apify.com/v2/key-value-stores/abc123/records/photographer_name_sunset_beach_001.jpg"
}
```

##### Video Output

```json
{
  "filename": "JoelOsteen_video_19.mp4",
  "filepath": "/usr/src/app/videos/JoelOsteen_video_19.mp4",
  "url": "https://x.com/JoelOsteen/status/1984289641667694621/video/1",
  "type": "video",
  "username": "JoelOsteen",
  "description": "video_19",
  "file_size_bytes": 9277111,
  "file_extension": ".mp4",
  "search_query": "Apple",
  "status": "downloaded",
  "download_timestamp": 1762867628.8281474,
  "public_url": "https://api.apify.com/v2/key-value-stores/abc123/records/JoelOsteen_video_19.mp4"
}
```

#### Key Fields

- **filename**: The saved filename of the media item
- **url**: Direct URL to the media on Twitter/X (images) or tweet URL (videos)
- **type**: Either `image` or `video`
- **username**: Twitter/X username of the poster
- **description**: Text from the tweet or title
- **search_query**: The search term that found this item
- **status**: Download status (`downloaded`, `pending`, `failed`)
- **size_bytes** (images) / **file_size_bytes** (videos): File size in bytes
- **content_type**: MIME type (images only)
- **file_extension**: Video format e.g. `.mp4` (videos only)
- **public_url**: Publicly accessible HTTPS URL for the file (both images and videos). Use this to download or embed media in external applications
- **download_timestamp**: Unix timestamp of when the video was downloaded (videos only)

### Pricing

- **Pay-As-You-Go**: Only pay for the compute units you use
- **Subscription Plans**: Discounted rates for high-volume usage

Check the [Apify Pricing Page](https://apify.com/pricing) for current rates.

### FAQs

**Q1: Does this actor work for all X.com/Twitter videos?**

A: It works for public tweets with videos. The actor downloads actual video files (not just metadata) and stores them with public URLs accessible via the `public_url` field in the output.

**Q2: Can I search for private account tweets?**

A: No, only public tweets are accessible. Private or restricted accounts are not supported due to X.com's privacy policies.

**Q3: Can I search multiple queries in one run?**

A: This actor processes one search query per run. For multiple queries, schedule separate runs or use Apify's batch processing.

**Q4: What's the difference between images, videos, and all?**

A:

- `images`: Tweets with image attachments only
- `videos`: Tweets with video/GIF content only
- `all`: Both image and video tweets

### Documentation

- [Apify SDK Documentation](https://docs.apify.com/sdk/python)

# Actor input Schema

## `searchQuery` (type: `string`):

Search query to find images on Twitter/X (e.g., 'alaska', 'nature photography')

## `limit` (type: `integer`):

Maximum number of images and videos to download

## `downloadImages` (type: `boolean`):

Whether to download images from tweets

## `downloadVideos` (type: `boolean`):

Whether to download videos from tweets (requires yt-dlp)

## `includeUsername` (type: `boolean`):

Include Twitter username in downloaded file names

## `includeDescription` (type: `boolean`):

Include tweet text/description in downloaded file names

## Actor input object example

```json
{
  "searchQuery": "nature",
  "limit": 20,
  "downloadImages": true,
  "downloadVideos": false,
  "includeUsername": true,
  "includeDescription": true
}
```

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("mwitiderrick/twitter-x-images-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 = {}

# Run the Actor and wait for it to finish
run = client.actor("mwitiderrick/twitter-x-images-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 '{}' |
apify call mwitiderrick/twitter-x-images-scrapper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,mwitiderrick/twitter-x-images-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/QzZgckg5YSfVxkkvk/builds/YWfpIc3XHrVoJWXGx/openapi.json
