# Twitter / X - Scraper - complete suite (`mikolabs/tweets-scraper`) Actor

Extract anything from X (Twitter) with high speed. This smart scraper auto-detects what to collect—tweets, profiles, users, lists, or media—and delivers clean, structured data instantly. Just enter usernames, URLs, or keywords and let automation do the rest.

- **URL**: https://apify.com/mikolabs/tweets-scraper.md
- **Developed by:** [mikolabs](https://apify.com/mikolabs) (community)
- **Categories:** Social media, Lead generation, Automation
- **Stats:** 97 total users, 2 monthly users, 100.0% runs succeeded, 2 bookmarks
- **User rating**: 5.00 out of 5 stars

## Pricing

from $20.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.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
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.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use 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

## Tweets-x-Scraper

Extract anything from X (Twitter) with speed and precision. This smart scraper auto-detects what to collect—tweets, profiles, users, lists, or media—and delivers clean, structured data instantly. Just enter usernames, URLs, or keywords and let automation do the rest.

### 🚀 Features

#### Smart Automatic Routing

The Actor **automatically detects** what you want to scrape based on your inputs:

- **Twitter Usernames** → Automatically scrapes profiles (smart mode detection)
- **Twitter List URLs** → Automatically scrapes list content
- **Search Terms** → Automatically searches tweets or users

#### Intelligent Profile Scraping

When scraping profiles, the Actor automatically selects the best mode:

- ✅ **Media Only Mode** - Check `Media Only` to extract only tweets with images/videos
- ✅ **With Replies Mode** - Enable `Include Replies` to get all tweets including replies
- ✅ **Normal Mode** - Standard tweet scraping (default)
- ✅ **Profile Search** - Add search terms to find specific content within profiles

#### Advanced Features


- 🎯 **Advanced Filtering** - Filter by date, location, media type, engagement metrics
- 👤 **Profile Information** - Extract complete profile details (bio, stats, avatar, banner)
- 📷 **Media Extraction** - Get direct URLs for images and videos with HLS preview links
- 📊 **Engagement Stats** - Collect likes, retweets, comments, and quotes
- 🔄 **Rate Limiting Protection** - Built-in retry logic and exponential backoff
- 📄 **Pagination** - Automatic handling of multiple pages
- 📋 **Structured Output** - Clean JSON output to Apify dataset

### 📋 Input Configuration

#### Main Input Fields

##### 1. Twitter Usernames
Add one or more Twitter usernames to scrape profiles. The Actor will automatically:
- Choose between normal, with-replies, or media-only mode based on your settings
- Apply profile search if search terms are provided

**Examples:**
````

elonmusk
apify
@naval (@ symbol is optional)

```

##### 2. Twitter List URLs
Add Twitter/X list URLs to scrape all tweets from lists.

**Supported formats:**
```

https://x.com/i/lists/123456
https://twitter.com/i/lists/123456
https://X (Twitter).net/i/lists/123456

```

##### 3. Search Terms
Add search queries to find tweets or users across Twitter.

**Examples:**
```

web scraping
AI technology
from:apify
\#python

````

#### Profile Options

- **Include Replies** - Include reply tweets (automatically switches to "with replies" mode)
- **Include Retweets** - Include retweets in results
- **Media Only** - Only scrape tweets containing images or videos (uses dedicated media scraper)

#### Search Options

When using Search Terms, choose what to search:
- **Search Tweets Globally** - Find tweets across all Twitter
- **Search Users** - Find Twitter accounts
- **Search Within Profiles** - Search for specific content in provided profiles (requires Twitter Usernames)

#### Content Filters

Filter tweets by content characteristics:
- **Only Images** - Filter tweets containing images
- **Only Videos** - Filter tweets containing videos
- **Only Verified Users** - Only include verified accounts
- **Only Quote Tweets** - Only include quote tweets
- **Include Native Retweets** - Include native retweets
- **Only Tweets with Links** - Filter tweets with external links
- **Safe Search** - Enable to filter sensitive content

#### Date & Location Filters

- **Start Date (From)** - Filter tweets from this date onwards (YYYY-MM-DD format)
- **End Date (Until)** - Filter tweets up to this date
- **Location Filter** - Filter by location (e.g., "Los Angeles", "New York")

#### Engagement Filters

Set minimum engagement thresholds:
- **Minimum Likes** - Minimum number of likes required
- **Minimum Replies** - Minimum number of replies required
- **Minimum Retweets** - Minimum number of retweets required

#### Limits & Pagination

- **Max Items to Scrape** - Maximum items (tweets/users) to collect (0 = unlimited)
- **Max Pages** - Maximum pages to scrape per handle/query

#### Advanced Options

- **Tweet Language** - Filter by language code (e.g., "en", "es", "fr")
- **Scrape Profile Info** - Extract detailed profile information
- **X (Twitter) Instance URL** - Custom X (Twitter) instance (advanced users)


### 🔧 Usage Examples

#### Example 1: Simple Profile Scraping

```json
{
  "twitterHandles": ["elonmusk", "apify"],
  "maxItems": 100
}
````

**What happens:** Scrapes the last 100 tweets from each profile using normal mode.

#### Example 2: Profile with Replies

```json
{
  "twitterHandles": ["elonmusk"],
  "includeReplies": true,
  "maxItems": 200
}
```

**What happens:** Automatically switches to "with replies" mode to get all tweets including replies.

#### Example 3: Media Only Scraping

```json
{
  "twitterHandles": ["apify", "elonmusk"],
  "mediaOnly": true
}
```

**What happens:** Uses the dedicated media scraper to extract only tweets with images/videos.

#### Example 4: Global Tweet Search with Filters

```json
{
  "searchTerms": ["web scraping", "#ai"],
  "searchType": "tweets",
  "startDate": "2024-01-01",
  "endDate": "2024-12-31",
  "onlyVerified": true,
  "minLikes": 10,
  "tweetLanguage": "en"
}
```

**What happens:** Searches for tweets globally with engagement and verification filters.

#### Example 5: Profile Search (Find Specific Content)

```json
{
  "twitterHandles": ["apify"],
  "searchTerms": ["scraping", "automation"],
  "searchType": "profile_tweets",
  "startDate": "2024-01-01"
}
```

**What happens:** Searches for specific keywords within the provided profile's tweets.

#### Example 6: Scrape Twitter List

```json
{
  "listUrls": ["https://x.com/i/lists/78783491"],
  "maxItems": 200
}
```

**What happens:** Scrapes up to 200 tweets from the specified list.

#### Example 7: User Search

```json
{
  "searchTerms": ["data scientist", "ML engineer"],
  "searchType": "users",
  "maxItems": 50
}
```

**What happens:** Finds Twitter users matching the search terms.

#### Example 8: Combined Scraping

```json
{
  "twitterHandles": ["apify"],
  "listUrls": ["https://x.com/i/lists/123456"],
  "searchTerms": ["web scraping"],
  "searchType": "tweets",
  "maxItems": 100
}
```

**What happens:** Scrapes all three: profile tweets, list tweets, and search results.

### 📊 Output Format

Data is saved to the Apify dataset with structured JSON objects:

#### Profile Output

```json
{
  "type": "profile",
  "username": "apify",
  "fullname": "Apify",
  "bio": "Web scraping and automation platform...",
  "stats": {
    "tweets": "1,234",
    "followers": "12.5K",
    "following": "567"
  },
  "avatar": "https://pbs.twimg.com/...",
  "banner": "https://pbs.twimg.com/...",
  "website": "https://apify.com",
  "location": "San Francisco, CA",
  "joined": "Joined January 2024",
  "scrape_date": "2024-10-24T12:00:00.000Z"
}
```

#### Tweet Output

```json
{
  "type": "tweet",
  "tweet_url": "https://x.com/apify/status/123456",
  "tweet_id": "123456",
  "profile_username": "apify",
  "author": {
    "fullname": "Apify",
    "username": "@apify",
    "avatar": "https://pbs.twimg.com/...",
    "verified": true,
    "verified_type": "blue"
  },
  "text": "Tweet content here...",
  "date": "Oct 24, 2024 · 12:00 PM UTC",
  "date_short": "Oct 24",
  "hashtags": ["#webscraping", "#automation"],
  "mentions": ["@user1", "@user2"],
  "urls": ["https://example.com"],
  "stats": {
    "comments": 12,
    "retweets": 34,
    "quotes": 5,
    "likes": 156
  },
  "media": [
    {
      "type": "video",
      "url": "https://video.twimg.com/...",
      "hls_preview": "https://hlsjs.video-dev.org/demo/?src=...",
      "thumbnail": "https://pbs.twimg.com/...",
      "requires_hls": false
    },
    {
      "type": "image",
      "url": "https://pbs.twimg.com/...",
      "thumbnail": "https://pbs.twimg.com/..."
    }
  ],
  "is_retweet": false,
  "scrape_date": "2024-10-24T12:00:00.000Z"
}
```

#### Media Tweet Output

```json
{
  "type": "media_tweet",
  "profile_username": "apify",
  "tweet_id": "123456",
  "media": [
    {
      "type": "image",
      "url": "https://pbs.twimg.com/...",
      "thumbnail": "https://pbs.twimg.com/..."
    }
  ],
  "stats": {
    "comments": 5,
    "retweets": 10,
    "quotes": 2,
    "likes": 45
  },
  "scrape_date": "2024-10-24T12:00:00.000Z"
}
```

#### User Search Output

```json
{
  "type": "user",
  "search_query": "data scientist",
  "username": "@john_doe",
  "fullname": "John Doe",
  "display_name": "John Doe",
  "handle": "@john_doe",
  "bio": "Data Scientist | ML Engineer...",
  "avatar": "https://pbs.twimg.com/...",
  "verified": true,
  "verified_type": "blue",
  "protected": false,
  "hashtags": ["#DataScience", "#ML"],
  "mentions": [],
  "urls": ["https://johndoe.com"],
  "profile_url": "https://x.com/john_doe",
  "scrape_date": "2024-10-24T12:00:00.000Z"
}
```

### 🛠️ Technical Details

#### Architecture

The Actor uses:

- **Smart Routing Logic** - Automatically detects scraping mode based on inputs
- **X (Twitter)** - Privacy-focused Twitter frontend for scraping
- **Apify SDK** - Full integration with Apify platform

#### Automatic Mode Detection

The Actor intelligently routes requests:

```
IF twitterHandles PROVIDED:
  IF mediaOnly = true → profile_media.py
  ELSE IF includeReplies OR includeRetweets → profile_with_reply.py
  ELSE → profile_main.py
  
  IF searchTerms PROVIDED AND searchType = "profile_tweets" → profile_search.py

IF listUrls PROVIDED → list_extractor.py

IF searchTerms PROVIDED (without twitterHandles):
  IF searchType = "tweets" → search_post.py
  ELSE IF searchType = "users" → search_user.py
```

#### Rate Limiting

- Automatic retry logic with exponential backoff
- Configurable delays between requests (4-8 seconds)
- Maximum retry attempts (default: 5)
- HTTP/2 connection pooling for efficiency

#### Proxy Support

- Automatic proxy rotation
- Configurable proxy groups and countries
- Fallback to non-proxy mode if configuration fails

### 📝 Notes

#### Limitations

- Scraping speed depends on X (Twitter) instance availability
- Some X (Twitter) instances may be rate-limited or temporarily blocked
- Historical data availability depends on X (Twitter) caching

#### Best Practices

2. **Set Reasonable Limits** - Use `maxItems` and `maxPages` to control scope
3. **Respect Delays** - The Actor includes automatic delays; don't circumvent them
4. **Monitor Runs** - Check logs for any issues with X (Twitter) instances
5. **Rotate Instances** - If one instance fails, try another in advanced settings
6. **Start Small** - Test with small limits before scaling up

### 🔐 Privacy & Ethics

This Actor uses X (Twitter), a privacy-focused Twitter frontend. Please ensure you:

- ✅ Comply with Twitter's Terms of Service
- ✅ Respect user privacy and data protection laws (GDPR, CCPA, etc.)
- ✅ Don't scrape personal/sensitive information withoutGot it 👍 Here’s your **cleaned-up README**
  This version is suitable for public release on Apify or GitHub:

***

## 🐦 Twitter Scraper – Smart Mode

A comprehensive Twitter scraper powered by **smart automatic detection**.
No mode selection needed — simply provide your inputs, and the Actor determines what to scrape automatically!

### 🚀 Features

#### Smart Mode Detection

The scraper **intelligently detects** what to extract based on the provided inputs:

- **Twitter Usernames** → Scrapes user profiles
- **List URLs** → Scrapes list content
- **Search Terms** → Finds tweets or users across Twitter

#### Flexible Profile Scraping

- ✅ **Media Only Mode** — Extract tweets with images/videos
- ✅ **Include Replies** — Get all tweets including replies
- ✅ **Standard Mode** — Regular tweet scraping
- ✅ **Profile Search** — Find specific content within a user’s profile

#### Advanced Capabilities

- 🎯 **Filtering Options** — By date, location, media, or engagement
- 👤 **Profile Info** — Get bio, stats, avatar, banner, and location
- 📷 **Media Extraction** — Collect URLs for images and videos
- 📊 **Engagement Stats** — Likes, retweets, comments, quotes
- 🔄 **Automatic Pagination** — Seamlessly fetch multiple pages
- 📋 **Structured Output** — Clean JSON format compatible with Apify datasets

***

### 📋 Input Configuration

#### Main Input Fields

##### 1. Twitter Usernames

Add one or more usernames to scrape profiles.
**Examples:**

```
elonmusk
apify
@naval
```

##### 2. Twitter List URLs

Scrape tweets from lists.
**Examples:**

```
https://x.com/i/lists/123456
https://twitter.com/i/lists/123456
```

##### 3. Search Terms

Search tweets or users globally.
**Examples:**

```
web scraping
AI technology
from:apify
#python
```

***

#### Profile Options

- **Include Replies** – Include reply tweets
- **Include Retweets** – Include retweets
- **Media Only** – Extract tweets with media only

#### Search Options

- **Search Tweets Globally**
- **Search Users**
- **Search Within Profiles** (requires usernames)

#### Filters

- **By Content** — images, videos, links, verified users
- **By Date** — start and end date
- **By Engagement** — likes, replies, retweets thresholds
- **By Language** — specify language codes (e.g., `en`, `es`)

***

### 🔧 Example Inputs

**Profile Scrape**

```json
{
  "twitterHandles": ["elonmusk"],
  "maxItems": 100
}
```

**Global Tweet Search**

```json
{
  "searchTerms": ["web scraping", "#ai"],
  "startDate": "2024-01-01",
  "endDate": "2024-12-31",
  "onlyVerified": true
}
```

**User Search**

```json
{
  "searchTerms": ["data scientist", "ML engineer"],
  "searchType": "users",
  "maxItems": 50
}
```

***

### 📊 Output Format

**Profile Example**

```json
{
  "type": "profile",
  "username": "apify",
  "fullname": "Apify",
  "bio": "Web scraping and automation platform...",
  "followers": "12.5K",
  "following": "567",
  "joined": "Joined January 2024"
}
```

**Tweet Example**

```json
{
  "type": "tweet",
  "tweet_url": "https://x.com/apify/status/123456",
  "username": "@apify",
  "text": "Tweet content here...",
  "hashtags": ["#webscraping"],
  "stats": {
    "likes": 150,
    "retweets": 30,
    "comments": 10
  }
}
```

**User Search Example**

```json
{
  "type": "user",
  "search_query": "data scientist",
  "username": "@john_doe",
  "fullname": "John Doe",
  "verified": true,
  "bio": "Data Scientist | ML Engineer"
}
```

***

### 🧩 Technical Overview

- **Smart Detection System** — Determines the correct scraping mode automatically
- **Flexible Input Types** — Supports usernames, lists, and search terms
- **Automatic Pagination** — Handles multiple pages seamlessly
- **Robust Filtering** — Date, engagement, and language filters

***

### ⚙️ Best Practices

- Use reasonable limits for `maxItems` and `maxPages`
- Always test small runs first
- Monitor logs for any warnings or skipped items
- Respect content and rate restrictions

***

### 🐛 Troubleshooting

**No data returned**

- Verify input format and spelling of usernames
- Try reducing filters (date or language)

**Empty media results**

- Ensure the target profile actually has media posts
- Disable `mediaOnly` to confirm tweets exist

**Search returns nothing**

- Simplify search terms
- Broaden filters or remove date limits

***

### 📚 Resources

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

***

### 🤝 Support

For help or feature requests:

- Contact Apify support
- Review Actor logs for details
- Recheck this README for usage instructions

***

### 📄 License

This Actor is provided as-is for use on the Apify platform.
Use responsibly and in accordance with all applicable data and platform policies.

***

Would you like me to **reword it slightly for Apify Marketplace tone** (shorter intro, feature bullets first, less technical details) or keep this as a **developer-oriented** version?
proper consent

- ✅ Use scraped data responsibly and ethically
- ✅ Implement appropriate rate limiting
- ✅ Don't overload servers or abuse the service

### 🐛 Troubleshooting

#### Issue: No data returned

**Solutions:**

- Check if the X (Twitter) instance is working (visit X (Twitter).net in browser)
- Try a different X (Twitter) instance in advanced settings
- Verify Twitter usernames exist and are spelled correctly

#### Issue: Rate limiting errors

**Solutions:**

- Increase delays between requests (default is already 4-8 seconds)
- Reduce `maxPages` parameter
- Try a different X (Twitter) instance

#### Issue: Proxy errors

**Solutions:**

- Verify proxy configuration is correct
- Ensure you have Apify proxy credits available
- Try different proxy groups/countries
- Check proxy group availability in Apify Console

#### Issue: Empty media results

**Solutions:**

- Ensure the profile actually has media tweets
- Try without `mediaOnly` filter to see all tweets first
- Check if the X (Twitter) instance properly displays media

#### Issue: Search returns no results

**Solutions:**

- Verify search terms are spelled correctly
- Try broader search terms
- Remove date filters to expand search range
- Try different search type (tweets vs users)

### 📚 Resources

- [X (Twitter) GitHub](https://github.com/zedeus/X "Twitter")
- \[X (Twitter) Instances List]\(https://github.com/zedeus/X (Twitter)/wiki/Instances)
- [Apify Documentation](https://docs.apify.com)
- [Apify SDK for Python](https://docs.apify.com/sdk/python)

### 🤝 Support

For issues, questions, or feature requests:

- Contact Apify support
- Check the Actor's logs for detailed error messages
- Review this documentation for troubleshooting steps

### 📄 License

This Actor is provided as-is for use on the Apify platform. Please ensure compliance with all applicable laws, terms of service, and ethical guidelines when using this tool.

### 🎯 Quick Start

1. Add Twitter usernames, list URLs, or search terms
2. Configure filters (optional)
3. Click "Start" - the Actor handles the rest automatically!

No mode selection needed - just provide your inputs and go! 🚀

# Actor input Schema

## `searchType` (type: `string`):

When using Search Terms, what to search for

## `twitterHandles` (type: `array`):

Enter Twitter usernames to scrape (with or without @). Example: elonmusk, apify

## `listUrls` (type: `array`):

Enter Twitter/X list URLs to scrape. Format: https://x.com/i/lists/123456 or https://twitter.com/i/lists/123456

## `searchTerms` (type: `array`):

Search queries to find tweets or users. For profile search, provide both username and search term. Examples: 'web scraping', 'AI', '#python'

## `includeReplies` (type: `boolean`):

Include reply tweets from profiles (automatically switches to 'with replies' mode)

## `includeRetweets` (type: `boolean`):

Include retweets in profile results (automatically switches to 'with replies' mode)

## `mediaOnly` (type: `boolean`):

Only scrape tweets that contain images or videos

## `maxItems` (type: `integer`):

Maximum number of items (tweets/users) to scrape. 0 = unlimited

## `maxPages` (type: `integer`):

Maximum number of pages to scrape per handle/query

## `startDate` (type: `string`):

Filter tweets from this date onwards (YYYY-MM-DD format)

## `endDate` (type: `string`):

Filter tweets up to this date (YYYY-MM-DD format)

## `location` (type: `string`):

Filter tweets by location (e.g., 'Los Angeles', 'New York', 'London')

## `onlyImages` (type: `boolean`):

Filter tweets that contain images

## `onlyVideos` (type: `boolean`):

Filter tweets that contain videos

## `onlyVerified` (type: `boolean`):

Only include tweets from verified accounts

## `onlyQuotes` (type: `boolean`):

Only include quote tweets

## `includeNativeRetweets` (type: `boolean`):

Include native retweets in search results

## `includeLinks` (type: `boolean`):

Filter tweets that contain external links

## `latestTweets` (type: `boolean`):

Only scrape tweets from the last 7 days

## `safeSearch` (type: `boolean`):

Enable safe search to filter sensitive content

## `minLikes` (type: `integer`):

Minimum number of likes a tweet must have

## `minReplies` (type: `integer`):

Minimum number of replies a tweet must have

## `minRetweets` (type: `integer`):

Minimum number of retweets a tweet must have

## `tweetLanguage` (type: `string`):

Filter by language code (e.g., 'en' for English, 'es' for Spanish, 'fr' for French)

## `scrapeProfileInfo` (type: `boolean`):

Extract detailed profile information (bio, stats, avatar, etc.)

## `useResidentialProxy` (type: `boolean`):

Enable Apify residential proxy for better reliability (requires Apify paid plan)

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

Apify proxy configuration (requires paid plan)

## `maxRetries` (type: `integer`):

Number of retry attempts for failed requests

## Actor input object example

```json
{
  "searchType": "tweets",
  "twitterHandles": [],
  "listUrls": [],
  "searchTerms": [
    "ocean"
  ],
  "includeReplies": false,
  "includeRetweets": true,
  "mediaOnly": false,
  "maxItems": 20,
  "maxPages": 2,
  "startDate": "",
  "endDate": "",
  "location": "",
  "onlyImages": false,
  "onlyVideos": false,
  "onlyVerified": false,
  "onlyQuotes": false,
  "includeNativeRetweets": true,
  "includeLinks": false,
  "latestTweets": false,
  "safeSearch": false,
  "minLikes": 0,
  "minReplies": 0,
  "minRetweets": 0,
  "tweetLanguage": "en",
  "scrapeProfileInfo": true,
  "useResidentialProxy": true,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  },
  "maxRetries": 5
}
```

# 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 = {
    "twitterHandles": [],
    "listUrls": [],
    "searchTerms": [
        "ocean"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("mikolabs/tweets-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 = {
    "twitterHandles": [],
    "listUrls": [],
    "searchTerms": ["ocean"],
}

# Run the Actor and wait for it to finish
run = client.actor("mikolabs/tweets-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "twitterHandles": [],
  "listUrls": [],
  "searchTerms": [
    "ocean"
  ]
}' |
apify call mikolabs/tweets-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=mikolabs/tweets-scraper",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Twitter / X - Scraper - complete suite",
        "description": "Extract anything from X (Twitter) with high speed. This smart scraper auto-detects what to collect—tweets, profiles, users, lists, or media—and delivers clean, structured data instantly. Just enter usernames, URLs, or keywords and let automation do the rest.",
        "version": "1.0",
        "x-build-id": "jadHCgI9sYhJZo5FC"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/mikolabs~tweets-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-mikolabs-tweets-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/mikolabs~tweets-scraper/runs": {
            "post": {
                "operationId": "runs-sync-mikolabs-tweets-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/mikolabs~tweets-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-mikolabs-tweets-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "proxyConfiguration"
                ],
                "properties": {
                    "searchType": {
                        "title": "Search Type",
                        "enum": [
                            "tweets",
                            "users",
                            "profile_tweets",
                            "complete_profile"
                        ],
                        "type": "string",
                        "description": "When using Search Terms, what to search for",
                        "default": "tweets"
                    },
                    "twitterHandles": {
                        "title": "Twitter Usernames",
                        "type": "array",
                        "description": "Enter Twitter usernames to scrape (with or without @). Example: elonmusk, apify",
                        "default": [],
                        "items": {
                            "type": "string"
                        }
                    },
                    "listUrls": {
                        "title": "Twitter List URLs",
                        "type": "array",
                        "description": "Enter Twitter/X list URLs to scrape. Format: https://x.com/i/lists/123456 or https://twitter.com/i/lists/123456",
                        "default": [],
                        "items": {
                            "type": "string"
                        }
                    },
                    "searchTerms": {
                        "title": "Search Terms",
                        "type": "array",
                        "description": "Search queries to find tweets or users. For profile search, provide both username and search term. Examples: 'web scraping', 'AI', '#python'",
                        "default": [
                            "ocean"
                        ],
                        "items": {
                            "type": "string"
                        }
                    },
                    "includeReplies": {
                        "title": "Include Replies",
                        "type": "boolean",
                        "description": "Include reply tweets from profiles (automatically switches to 'with replies' mode)",
                        "default": false
                    },
                    "includeRetweets": {
                        "title": "Include Retweets",
                        "type": "boolean",
                        "description": "Include retweets in profile results (automatically switches to 'with replies' mode)",
                        "default": true
                    },
                    "mediaOnly": {
                        "title": "Media Only",
                        "type": "boolean",
                        "description": "Only scrape tweets that contain images or videos",
                        "default": false
                    },
                    "maxItems": {
                        "title": "Max Items to Scrape",
                        "minimum": 1,
                        "type": "integer",
                        "description": "Maximum number of items (tweets/users) to scrape. 0 = unlimited",
                        "default": 20
                    },
                    "maxPages": {
                        "title": "Max Pages",
                        "minimum": 0,
                        "maximum": 100,
                        "type": "integer",
                        "description": "Maximum number of pages to scrape per handle/query",
                        "default": 2
                    },
                    "startDate": {
                        "title": "Start Date (From) [YYYY-MM-DD]",
                        "type": "string",
                        "description": "Filter tweets from this date onwards (YYYY-MM-DD format)",
                        "default": ""
                    },
                    "endDate": {
                        "title": "End Date (Until) [YYYY-MM-DD]",
                        "type": "string",
                        "description": "Filter tweets up to this date (YYYY-MM-DD format)",
                        "default": ""
                    },
                    "location": {
                        "title": "Location Filter",
                        "type": "string",
                        "description": "Filter tweets by location (e.g., 'Los Angeles', 'New York', 'London')",
                        "default": ""
                    },
                    "onlyImages": {
                        "title": "Only Images",
                        "type": "boolean",
                        "description": "Filter tweets that contain images",
                        "default": false
                    },
                    "onlyVideos": {
                        "title": "Only Videos",
                        "type": "boolean",
                        "description": "Filter tweets that contain videos",
                        "default": false
                    },
                    "onlyVerified": {
                        "title": "Only Verified Users",
                        "type": "boolean",
                        "description": "Only include tweets from verified accounts",
                        "default": false
                    },
                    "onlyQuotes": {
                        "title": "Only Quote Tweets",
                        "type": "boolean",
                        "description": "Only include quote tweets",
                        "default": false
                    },
                    "includeNativeRetweets": {
                        "title": "Include Native Retweets",
                        "type": "boolean",
                        "description": "Include native retweets in search results",
                        "default": true
                    },
                    "includeLinks": {
                        "title": "Only Tweets with Links",
                        "type": "boolean",
                        "description": "Filter tweets that contain external links",
                        "default": false
                    },
                    "latestTweets": {
                        "title": "Latest Tweets Only (Last 7 Days)",
                        "type": "boolean",
                        "description": "Only scrape tweets from the last 7 days",
                        "default": false
                    },
                    "safeSearch": {
                        "title": "Safe Search",
                        "type": "boolean",
                        "description": "Enable safe search to filter sensitive content",
                        "default": false
                    },
                    "minLikes": {
                        "title": "Minimum Likes",
                        "minimum": 0,
                        "type": "integer",
                        "description": "Minimum number of likes a tweet must have",
                        "default": 0
                    },
                    "minReplies": {
                        "title": "Minimum Replies",
                        "minimum": 0,
                        "type": "integer",
                        "description": "Minimum number of replies a tweet must have",
                        "default": 0
                    },
                    "minRetweets": {
                        "title": "Minimum Retweets",
                        "minimum": 0,
                        "type": "integer",
                        "description": "Minimum number of retweets a tweet must have",
                        "default": 0
                    },
                    "tweetLanguage": {
                        "title": "Tweet Language",
                        "type": "string",
                        "description": "Filter by language code (e.g., 'en' for English, 'es' for Spanish, 'fr' for French)",
                        "default": ""
                    },
                    "scrapeProfileInfo": {
                        "title": "Scrape Profile Info",
                        "type": "boolean",
                        "description": "Extract detailed profile information (bio, stats, avatar, etc.)",
                        "default": true
                    },
                    "useResidentialProxy": {
                        "title": "Use Residential Proxy",
                        "type": "boolean",
                        "description": "Enable Apify residential proxy for better reliability (requires Apify paid plan)",
                        "default": true
                    },
                    "proxyConfiguration": {
                        "title": "Proxy Configuration",
                        "type": "object",
                        "description": "Apify proxy configuration (requires paid plan)",
                        "default": {
                            "useApifyProxy": true,
                            "apifyProxyGroups": [
                                "RESIDENTIAL"
                            ]
                        }
                    },
                    "maxRetries": {
                        "title": "Max Retries per Request",
                        "minimum": 1,
                        "maximum": 10,
                        "type": "integer",
                        "description": "Number of retry attempts for failed requests",
                        "default": 5
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
