# X (Twitter) Search Scraper (`desearch/ai-twitter-search`) Actor

The Basic X Search API enables users to retrieve relevant links and tweets based on specified search queries without utilizing AI-driven models. It analyzes links from X posts that align with the provided search criteria

- **URL**: https://apify.com/desearch/ai-twitter-search.md
- **Developed by:** [Desearch](https://apify.com/desearch) (community)
- **Categories:** Social media, Developer tools
- **Security:** Full permissions
- **Stats:** 375 total users, 1 monthly users, 100.0% runs succeeded, 7 bookmarks
- **User rating**: 5.00 out of 5 stars

## Pricing

$0.30 / 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

## 📢 Datura AI Twitter Search Actor - Apify

**Effortlessly search X (Twitter) for tweets matching your query!**

[![Apify Actor](https://img.shields.io/badge/Apify-Actor-blue?logo=apify)](https://apify.com)

[![Made with ❤️](https://img.shields.io/badge/Made%20with-%E2%9D%A4-red)](https://datura.ai)

### 🚀 Overview

This Apify actor allows users to search tweets using the **Basic X (Twitter) Search API** from [Datura.ai](https://console.datura.ai/). With this tool, you can extract tweets based on various filters such as keywords, engagement metrics, dates, and media types.

### 🛠 Features

✅ Search tweets using **advanced query operators**\
✅ Filter results by **language, engagement, date, and media type**\
✅ Retrieve **tweet details**, including user info, retweets, and likes\
✅ **Exclude** images, videos, or quotes\
✅ Fetch up to **100 tweets per query**

### 📌 How to Use

1️⃣ **Open the Apify Actor UI**\
2️⃣ **Configure search parameters** (e.g., query, date range, filters)\
3️⃣ **Run the actor** and retrieve tweets\
4️⃣ **Download results** in JSON format

### 📌 Input Parameters

| Parameter      | Type    | Required | Description |
|---------------|--------|----------|-------------|
| `query`       | String | ✅ Yes    | Search term (e.g., `"Bittensor"`). Use [Twitter Search Operators](https://docs.datura.ai/guides/capabilities/twitter-queries) for advanced queries. |
| `sort`        | String | ❌ No     | Sort by `"Top"` or `"Latest"` (default: `"Top"`). |
| `start_date`  | String | ❌ No     | Start date (`YYYY-MM-DD`). |
| `end_date`    | String | ❌ No     | End date (`YYYY-MM-DD`). |
| `lang`        | String | ❌ No     | Language filter (`en`, `fr`, `es`, etc.). |
| `min_likes`   | Number | ❌ No     | Minimum number of likes. |
| `min_retweets`| Number | ❌ No     | Minimum number of retweets. |
| `min_replies` | Number | ❌ No     | Minimum number of replies. |
| `blue_verified` | Boolean | ❌ No  | Filter for **Twitter Blue** users (default: `false`). |
| `is_image`    | Boolean | ❌ No     | Include tweets with images (`true/false`). |
| `is_video`    | Boolean | ❌ No     | Include tweets with videos (`true/false`). |
| `count`       | Number | ❌ No     | Number of tweets to retrieve (default: `10`, max: `100`). |

### 📥 Expected Output

The actor outputs **a JSON file** containing the retrieved tweets. Example format:

```json
[
  {
    "user": {
      "id": "1453417787746029577",
      "url": "https://x.com/firsttensor",
      "name": "Firsττensor - Biττensor Validator",
      "username": "firsttensor",
      "created_at": "2021-10-27",
      "followers_count": 4669,
      "profile_image_url": "https://pbs.twimg.com/profile_images/1890150870563614720/L3PGGoUs_normal.jpg"
    },
    "id": "1891203972003684353",
    "text": "How to Stake/Unstake $TAO to the FirstTensor Validator...",
    "retweet_count": 2,
    "like_count": 7,
    "created_at": "2025-02-16",
    "url": "https://x.com/firsttensor/status/1891203972003684353",
    "hashtags": ["bittensor", "delegate", "root"]
  }
]
```

### 📌 Twitter Search Operators

This actor supports **Twitter's advanced search operators** to refine results.\
🔍 **Examples:**

- `#hashtag` → Tweets with a specific hashtag
- `from:user` → Tweets from a specific user
- `min_retweets:10` → Tweets with at least 10 retweets
- `filter:videos` → Tweets with videos
- `since:YYYY-MM-DD` → Tweets from a certain date

For a complete list, check [Twitter Advanced Search](https://docs.datura.ai/guides/capabilities/twitter-queries).

### 📈 Use Cases

💡 **Market Research:** Find trending tweets on a topic.\
💡 **Brand Monitoring:** Track mentions of your brand.\
💡 **Crypto & Finance Analysis:** Follow discussions on tokens.\
💡 **News Scraping:** Collect tweets from verified sources.

### 🚀 Get Started

1️⃣ Open the **Apify Actor UI**\
2️⃣ Enter your search parameters\
3️⃣ Run the actor and collect tweets effortlessly!

### 🛠 Support

For questions or issues, check [Datura Docs](https://docs.datura.ai/guides/capabilities/twitter-search).

# Actor input Schema

## `query` (type: `string`):

The Twitter search query.

## `blue_verified` (type: `boolean`):

Filter results to include only blue verified accounts.

## `start_date` (type: `string`):

Select start date in format YYYY-MM-DD

## `end_date` (type: `string`):

Select end date in format YYYY-MM-DD

## `is_image` (type: `boolean`):

Filter tweets that contain images.

## `is_quote` (type: `boolean`):

Filter tweets that are quotes.

## `is_video` (type: `boolean`):

Filter tweets that contain videos.

## `lang` (type: `string`):

Filter tweets by language (e.g., en, fr, ar).

## `min_likes` (type: `integer`):

Filter tweets with at least this number of likes.

## `min_replies` (type: `integer`):

Filter tweets with at least this number of replies.

## `min_retweets` (type: `integer`):

Filter tweets with at least this number of retweets.

## `sort` (type: `string`):

Sort tweets by Latest or Top.

## `count` (type: `integer`):

Number of tweets to retrieve.

## Actor input object example

```json
{
  "query": "bittensor",
  "blue_verified": false,
  "is_image": false,
  "is_quote": false,
  "is_video": false,
  "lang": "en",
  "min_likes": 0,
  "min_replies": 0,
  "min_retweets": 0,
  "sort": "Latest",
  "count": 20
}
```

# 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("desearch/ai-twitter-search").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("desearch/ai-twitter-search").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 desearch/ai-twitter-search --silent --output-dataset

```

## MCP server setup

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

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/JZPB1o5RWTUHsBhgB/builds/N4NSOg6DF0fdrICOb/openapi.json
