# Twitter Trends Scraper (`khadinakbar/twitter-trends-scraper`) Actor

Collect X (Twitter) trending topics by country, city, or worldwide with historical snapshots, rank history, source URLs, and retrieval timestamps.

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

## Pricing

from $0.50 / 1,000 trend scrapeds

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/actors/running/actors-in-store.md#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

## Twitter Trends Scraper

Scrape real-time X (Twitter) trending topics by country, city, or worldwide — with optional historical windows (1h to 7d), batch multi-location mode, and category-aware output. HTTP-only via `getdaytrends.com`, no login, no API key. MCP-ready for AI agents.

> Returns the public trends board that X shows on its "What's happening" page. Does not require Twitter login, developer account, or any API key.

***

### What you get

- **Real-time Top 50 trends** for Worldwide + 138 supported locations (countries + major cities).
- **Historical snapshots** at 1h, 2h, 3h, 6h, 12h, 24h, 2d, 3d, 7d, or a custom UTC datetime.
- **Multi-location batch** in a single run — useful for cross-market comparisons.
- **Compact sparkline history** — last 8 hours of rank trajectory per trend, when available.
- **Deduplication mode** — collapse repeats across locations into one row with `locations[]`.
- **Direct `x.com/search` URLs** for each trend — ready for downstream content workflows.

Each dataset row is one trend at one rank, one location, one time window. Records are flat and agent-friendly.

***

### Sample output

```json
{
  "recordType": "trend",
  "rank": 1,
  "name": "Dodgers",
  "hashtag": false,
  "url": "https://getdaytrends.com/united-states/trend/Dodgers/",
  "searchUrl": "https://x.com/search?q=Dodgers",
  "volume": null,
  "volumeLabel": null,
  "category": null,
  "promoted": false,
  "location": "United States",
  "locationSlug": "united-states",
  "woeid": 23424977,
  "windowLabel": "Now",
  "windowHoursBack": 0,
  "windowTimestamp": null,
  "history": [
    { "t": "2026-08-02T15:00:00.000Z", "rank": 1 },
    { "t": "2026-08-02T14:00:00.000Z", "rank": 1 }
  ],
  "source": "getdaytrends",
  "scrapedAt": "2026-08-02T16:12:34.000Z"
}
```

***

### Input

| Field | Type | Default | Description |
|---|---|---|---|
| `locations` | string\[] | `["worldwide"]` | Slugs (`united-states`), display names (`Brazil`), full URLs, or WOEIDs (`23424977`). |
| `window` | enum | `now` | `now`, `1h`, `2h`, `3h`, `6h`, `12h`, `24h`, `2d`, `3d`, `7d`, `custom`. |
| `customDateTime` | string | — | UTC `YYYY-MM-DD HH` (used only when `window=custom`). |
| `maxTrendsPerLocation` | integer | `50` | Cap per location/window. |
| `hashtagOnly` | boolean | `false` | Only return `#hashtag` trends. |
| `deduplicateAcrossLocations` | boolean | `false` | Collapse repeats into one row with `locations[]`. |
| `includeHistory` | boolean | `true` | Attach `history[]` sparkline samples. |
| `listAvailableLocations` | boolean | `false` | Return the supported-locations catalog instead of trends. |

***

### Pricing — Pay per event + usage

| Event | Price |
|---|---|
| Actor start | $0.00005 |
| Trend scraped | $0.0005 |

**Typical run (Worldwide, Now, 50 trends):** 1 × $0.00005 + 50 × $0.0005 = **~$0.025** + Apify platform usage.

**Multi-location batch (5 locations × 50 trends):** 1 × $0.00005 + 250 × $0.0005 = **~$0.125** + usage.

Platform usage (compute + proxy) is billed through via `isPPEPlatformUsagePaidByUser: true`. getdaytrends is HTTP-only and rarely WAF-protected, so residential proxy usage is minimal in practice.

***

### Use cases

- **Social-listening dashboards** — pump Worldwide + top 10 markets into a monitoring stack every 15 minutes.
- **Newsrooms** — surface breaking trends before they hit the wire.
- **Creator/content teams** — match trends to existing editorial calendars via the `searchUrl`.
- **Market researchers** — compare the same time window across LATAM, EU, and APAC.
- **AI agents** — clean, narrow JSON, one verb ("get trends"), under 500 tokens per item.

***

### How it works

1. Builds a `getdaytrends.com/{slug}/{window}/` URL per requested location.
2. Fetches server-rendered HTML with `HttpCrawler` (Cheerio-style regex parsing — no headless browser needed).
3. Extracts rank, name, URL, and the inline sparkline `<polyline points>` for trajectory.
4. Charges per dataset row pushed.
5. Writes `OUTPUT` and `RUN_SUMMARY` to the key-value store with `COMPLETE`, `PARTIAL`, `VALID_EMPTY`, `INVALID_INPUT`, or `UPSTREAM_FAILED` outcome.

No X login. No Twitter developer account. No third-party API key required.

***

### MCP / Agent usage

**Tool description (what an LLM sees):**

> Scrape real-time X (Twitter) trending topics by country, city, or worldwide — with optional historical windows (1h to 7d). Use for social monitoring, news tracking, content planning. Returns trend name, rank, hashtag flag, search URL, and optional sparkline history. Charged $0.0005/trend + $0.00005 start.

**Agent-friendly example:**

```json
{
  "locations": ["worldwide", "united-states", "japan"],
  "window": "now",
  "maxTrendsPerLocation": 20,
  "includeHistory": false
}
```

Returns 60 rows (~$0.03 + usage). Agent can confidently predict cost from `maxTrendsPerLocation × len(locations)`.

***

### API example

```bash
curl -XPOST -H "Authorization: Bearer $APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  "https://api.apify.com/v2/acts/khadinakbar.twitter-trends-scraper/runs?token=$APIFY_TOKEN" \
  -d '{"locations":["worldwide"],"window":"now","maxTrendsPerLocation":50}'
```

Results: `https://api.apify.com/v2/datasets/{DATASET_ID}/items`

***

### Available locations

138 supported. Set `listAvailableLocations: true` to dump the full catalog (slug, displayName, country, countryCode, woeid) as dataset rows. Highlights: Worldwide (1), United States (23424977), United Kingdom (23424775), Japan (23424856), Brazil (23424762), India (23424848), Germany (23424829), France (23424819), plus 130 country/city entries.

***

### Legal disclaimer

This actor scrapes publicly available trend data from a third-party aggregator (getdaytrends.com) that mirrors the public X (Twitter) trends board. It does not access private accounts, authenticated endpoints, or login-protected content. Trend names and rankings are public. Users are responsible for complying with the terms of service of X (Twitter), getdaytrends.com, and applicable laws in their jurisdiction. The actor is provided for research, journalism, marketing intelligence, and similar legitimate purposes.

# Actor input Schema

## `locations` (type: `array`):

List of locations to scrape trends for. Accepts slug strings (e.g. 'worldwide', 'united-states', 'japan'), display names (e.g. 'United States', 'Brazil'), full getdaytrends URLs (e.g. https://getdaytrends.com/united-states/), or WOEID integers (e.g. 23424977 for the United States, 1 for Worldwide). Defaults to Worldwide. To list every available location once with zero trends, set listAvailableLocations=true instead.

## `window` (type: `string`):

Which snapshot to fetch. 'now' returns the live Top 50. '1h', '3h', '6h', '12h', '24h', '2d', '3d', '7d' return historical snapshots for the same location(s). 'custom' uses customDateTime. Defaults to 'now'. NOT a tweet-posted filter - it is the timestamp at which the trend board was captured.

## `customDateTime` (type: `string`):

Used only when window='custom'. UTC timestamp in 'YYYY-MM-DD HH' (24h) or full ISO format. Example: '2026-08-01 16' returns the snapshot from Aug 1, 2026 at 16:00 UTC. Earliest supported date is 2024-05-15.

## `maxTrendsPerLocation` (type: `integer`):

Cap on the number of trend rows returned per location per window. Source returns up to 50; lower values reduce cost. Default 50.

## `hashtagOnly` (type: `boolean`):

When true, only trends starting with '#' are returned. Useful for hashtag-driven campaigns. Default false.

## `deduplicateAcrossLocations` (type: `boolean`):

When true and multiple locations are scraped, repeats of the same trend name across locations collapse to a single row with a 'locations\[]' array. Default false (keeps one row per location, useful for market comparison).

## `includeHistory` (type: `boolean`):

When true, attaches a compact 'history\[]' array of (timestamp, rank) samples parsed from the source sparkline. Adds tokens, useful for trend trajectory analysis. Default true.

## `listAvailableLocations` (type: `boolean`):

When true, the actor returns the full catalog of supported locations (slug, displayName, country, woeid) as dataset rows and skips trend scraping. Default false.

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

Proxy servers used for HTTP requests. Defaults to Apify residential. getdaytrends is rarely WAF-protected so datacenter often works; switch to RESIDENTIAL only if you hit blocks.

## Actor input object example

```json
{
  "locations": [
    "worldwide",
    "united-states",
    "japan"
  ],
  "window": "now",
  "customDateTime": "2026-08-01 16",
  "maxTrendsPerLocation": 50,
  "hashtagOnly": false,
  "deduplicateAcrossLocations": false,
  "includeHistory": true,
  "listAvailableLocations": false,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}
```

# Actor output Schema

## `results` (type: `string`):

Dataset items containing one record per trend per location per time window.

## `summary` (type: `string`):

Run summary including trends scraped, location counts, window usage, charge counts, and source diagnostics.

## `runSummary` (type: `string`):

Same payload persisted under the RUN\_SUMMARY key for run-evidence workflows.

# 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 = {
    "locations": [
        "worldwide"
    ],
    "window": "now",
    "maxTrendsPerLocation": 50,
    "hashtagOnly": false,
    "deduplicateAcrossLocations": false,
    "includeHistory": true,
    "listAvailableLocations": false,
    "proxyConfiguration": {
        "useApifyProxy": true,
        "apifyProxyGroups": [
            "RESIDENTIAL"
        ]
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("khadinakbar/twitter-trends-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 = {
    "locations": ["worldwide"],
    "window": "now",
    "maxTrendsPerLocation": 50,
    "hashtagOnly": False,
    "deduplicateAcrossLocations": False,
    "includeHistory": True,
    "listAvailableLocations": False,
    "proxyConfiguration": {
        "useApifyProxy": True,
        "apifyProxyGroups": ["RESIDENTIAL"],
    },
}

# Run the Actor and wait for it to finish
run = client.actor("khadinakbar/twitter-trends-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 '{
  "locations": [
    "worldwide"
  ],
  "window": "now",
  "maxTrendsPerLocation": 50,
  "hashtagOnly": false,
  "deduplicateAcrossLocations": false,
  "includeHistory": true,
  "listAvailableLocations": false,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}' |
apify call khadinakbar/twitter-trends-scraper --silent --output-dataset

```

## MCP server setup

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