# Search Threads By Keywords (`watcher.data/search-threads-by-keywords`) Actor

Fast and reliable scraper for searching posts on Threads by Meta. Perfect for social media monitoring, research, and business intelligence.

- **URL**: https://apify.com/watcher.data/search-threads-by-keywords.md
- **Developed by:** [Giichi Arai](https://apify.com/watcher.data) (community)
- **Categories:** Automation, Social media, Integrations
- **Features:** Limited permissions
- **Stats:** 37,223 total users, 704 monthly users, 100.0% runs succeeded, 27 bookmarks
- **User rating**: 3.44 out of 5 stars

## Pricing

$8.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

## Search Threads by Keywords

Fast and reliable scraper for searching posts on Threads by Meta. Supports multiple output formats (JSON, CSV, Excel), advanced filtering options, and real-time data extraction. Perfect for social media monitoring, research, and business intelligence.

### Features

- 🔍 **Keyword-based Search**: Search for posts using multiple keywords, hashtags, usernames, or phrases
- 📊 **Multiple Output Formats**: Export data in JSON, CSV, or Excel format
- 🔄 **Real-time Data**: Get the latest posts from Threads
- 📈 **Engagement Metrics**: Collect likes, replies, reposts, quotes, and view counts
- 🎯 **Advanced Filtering**: Sort by recent or relevant posts
- 🚀 **High Performance**: Fast API-powered scraping with pagination support
- 🔄 **Deduplication**: Automatically removes duplicate posts across keywords

### Input Parameters

#### Required Fields

- **Search Keywords** (`keywords`): Array of keywords to search for
  - Examples: `["#AI", "Python", "Meta", "@username"]`
  - Each keyword is searched separately via individual API calls

#### Optional Fields

- **Maximum Items Per Keyword** (`maxItemsPerKeyword`): Maximum number of posts per keyword (1-2000, default: 50)
- **Sort By Recent** (`sortByRecent`): Sort by recent posts (true) or relevant posts (false, default: true)
- **Output Format** (`outputFormat`): Choose output format - JSON, CSV, or Excel (default: JSON)
- **Proxy Configuration** (`proxyConfiguration`): Proxy settings for requests

### Output Data

Each post includes the following fields:

#### Basic Information

- `id`: Unique post identifier
- `text`: Post content/caption
- `author`: Username of the post author
- `author_name`: Display name of the author
- `author_id`: Unique author identifier
- `created_at`: Post creation timestamp

#### Engagement Metrics

- `like_count`: Number of likes
- `reply_count`: Number of replies
- `repost_count`: Number of reposts
- `quote_count`: Number of quotes
- `view_count`: Number of views

#### Content Analysis

- `hashtags`: List of hashtags used
- `mentions`: List of mentioned users
- `urls`: List of URLs in the post
- `media`: List of media attachments
- `lang`: Language of the post

#### Metadata

- `is_reply`: Whether the post is a reply
- `is_repost`: Whether the post is a repost
- `url`: Direct link to the post
- `verified`: Whether the author is verified
- `follower_count`: Author's follower count
- `following_count`: Author's following count

### Usage Examples

#### Basic Search

```json
{
  "keywords": ["#AI", "Python", "Meta"],
  "maxItemsPerKeyword": 100,
  "sortByRecent": true,
  "outputFormat": "json"
}
```

#### Advanced Configuration

```json
{
  "keywords": ["#MachineLearning", "@meta", "artificial intelligence"],
  "maxItemsPerKeyword": 200,
  "sortByRecent": false,
  "outputFormat": "excel",
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}
```

#### Multiple Keywords Example

```json
{
  "keywords": [
    "#TechNews",
    "#Innovation",
    "#Startup",
    "@elonmusk",
    "blockchain"
  ],
  "maxItemsPerKeyword": 50,
  "sortByRecent": true,
  "outputFormat": "csv"
}
```

### API Endpoint

This actor uses the `/threads/search/posts` endpoint with the following parameters:

- `query`: Search query string
- `cursor`: Pagination cursor for next page (optional)
- `recent`: Sort by recent (1) or relevant (0) posts

### Performance Notes

- The scraper uses pagination to collect large datasets efficiently
- Automatic retry logic with exponential backoff for reliability
- Rate limiting between requests to be respectful to the API
- Deduplication removes duplicate posts when using multiple keywords
- Maximum 20 items per API call for optimal performance

### Output Formats

#### JSON (Default)

- Complete data including all fields and raw API response
- Best for programmatic processing and analysis

#### CSV

- Clean tabular format without raw data
- Perfect for spreadsheet analysis and data visualization

#### Excel (XLSX)

- Professional format with proper data types
- Ideal for business reports and presentations

### Error Handling

The actor includes comprehensive error handling:

- Automatic retry on network failures
- Graceful handling of API rate limits
- Detailed logging for troubleshooting
- Validation of input parameters

### Support

For questions, issues, or feature requests, please contact our support team or create an issue in the repository.

### License

This project is licensed under the Apache-2.0 License.

# Actor input Schema

## `keywords` (type: `array`):

Enter keywords to search for (hashtags, usernames, phrases, etc.). Each keyword will be searched separately via individual API calls.

## `maxItemsPerKeyword` (type: `integer`):

Maximum number of posts to retrieve for each individual keyword (after deduplication across keywords)

## `sortByRecent` (type: `boolean`):

Sort posts by recent (true) or relevant (false)

## `outputFormat` (type: `string`):

Choose the output format for downloaded data

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

Proxy settings for requests

## Actor input object example

```json
{
  "keywords": [
    "#AI",
    "Meta"
  ],
  "maxItemsPerKeyword": 10,
  "sortByRecent": true,
  "outputFormat": "json",
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}
```

# 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 = {
    "keywords": [
        "#AI",
        "Meta"
    ],
    "proxyConfiguration": {
        "useApifyProxy": false
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("watcher.data/search-threads-by-keywords").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 = {
    "keywords": [
        "#AI",
        "Meta",
    ],
    "proxyConfiguration": { "useApifyProxy": False },
}

# Run the Actor and wait for it to finish
run = client.actor("watcher.data/search-threads-by-keywords").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 '{
  "keywords": [
    "#AI",
    "Meta"
  ],
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}' |
apify call watcher.data/search-threads-by-keywords --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,watcher.data/search-threads-by-keywords"
        }
    }
}
```

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/D15iJFBNZ9wgeWAhw/builds/1DnddRMgp9RfKtGcU/openapi.json
