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

Twitter trends scraper: X trending topics for worldwide and 466 countries and cities, several per run, now and hour by hour for the last 24 hours, with rank, first-seen time, duration, best rank and previous rank. Monitor mode alerts on new topics entering the top N.

- **URL**: https://apify.com/datahamster/twitter-trends-scraper.md
- **Developed by:** [Viktor Dubnytskiy](https://apify.com/datahamster) (community)
- **Categories:** Social media, Marketing
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.80 / 1,000 result items

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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 Trends Scraper

Get what is trending on X (Twitter) right now and over the last 24 hours, for worldwide and any of 466 countries and cities, several of them in one run. Each row is one trending topic in one hourly top-50 snapshot with its rank, the time the snapshot was taken, when the topic first entered the list, how long it has stayed there, its best rank and its rank an hour earlier.

**Try it:** the prefilled example returns 20 rows in about 4 seconds and costs about $0.020. Results cost $1 per 1,000.

Coverage limits: trends come from trends24.in, which keeps 24 snapshots per location (on 05.11.2026 they covered the last 17 to 24 hours, roughly one per hour). X stopped showing tweet counts in January 2026, so `tweetVolume` is empty unless a source shows a count again.

### Why this one

- **The life of each trend.** Every row carries `firstSeenAt`, `durationHours`, `bestRank`, `bestRankAt`, `previousRank` (rank in the snapshot an hour earlier), `isNewEntry` and `snapshotsInTop`, worked out from the location's last ~24 hourly snapshots. The two most used trends actors on the Store do not return these: karamelo's rows are `trend`, `time`, `timePeriod` and `volume` (no rank), automation-lab's are the current list with rank, `tweetVolume`, hashtag flag and links. On 05.11.2026 the US row for "Hegseth" read: rank 3, first seen 01:30 UTC, trending 16.3 hours, best rank 2, rank 3 an hour earlier.
- **Alerts on new topics only.** Monitor mode returns only topics that entered a location's top N and were nowhere in its top 50 on any run during the last day, with an optional webhook or Telegram message. Reordering inside the list and topics hovering at the edge of the top N do not alert. Neither leader has this: automation-lab suggests scheduling runs and diffing them yourself, karamelo has no scheduling guidance.
- **Every hourly snapshot, not fixed points.** `hoursBack` (1 to 24) returns each hourly top 50 in that window. karamelo returns fixed points (live, 1, 3, 6, 12 and 24 hours, 2 and 3 days ago), automation-lab only the current list. A test run on 05.11.2026 with `hoursBack: 24` returned 3,066 rows for the United States, Tokyo and London (20 to 22 distinct hourly snapshots each, one page request per location) in 76 seconds.
- **Fallback.** If trends24 refuses a country or worldwide page, the actor reads the current top 50 from getdaytrends.com instead (`source: "getdaytrends"`, no history fields).
- **Locations:** worldwide, 62 countries and 404 cities, several per run, by name ("Japan", "New York", "London, United Kingdom") or trends24 slug. automation-lab covers the same 467 locations; karamelo covers 35 countries, one per run.

What it does not do: history beyond ~24 hours (karamelo reaches 3 days back at fixed points), WOEID numbers as input, tweet counts (X hides them).

### What you get

One row per topic per snapshot:

| location | snapshotAt | rank | name | firstSeenAt | durationHours | bestRank | previousRank |
|---|---|---|---|---|---|---|---|
| Worldwide | 2026-11-05T20:21:06Z | 1 | Paraguay | 2026-11-05T16:52:13Z | 3.5 | 1 | 1 |
| Worldwide | 2026-11-05T20:21:06Z | 2 | Santiago Peña | 2026-11-05T16:01:08Z | 4.3 | 2 | 2 |
| Worldwide | 2026-11-05T20:21:06Z | 3 | Aldosivi | 2026-11-05T18:36:18Z | 1.7 | 3 | 6 |
| United States | 2026-11-05T20:27:24Z | 1 | Harmeet | 2026-11-05T19:33:22Z | 0.9 | 1 | 1 |
| United States | 2026-11-05T20:27:24Z | 2 | Russell Brand | 2026-11-05T15:16:05Z | 5.2 | 1 | 2 |
| United States | 2026-11-05T20:27:24Z | 3 | Carson Wentz | 2026-11-05T18:40:17Z | 1.8 | 3 | 3 |

A full row:

```json
{
  "id": "united-states|1793910444|2",
  "url": "https://trends24.in/united-states/",
  "location": "United States",
  "locationSlug": "united-states",
  "locationType": "country",
  "country": "United States",
  "snapshotAt": "2026-11-05T20:27:24Z",
  "rank": 2,
  "name": "Russell Brand",
  "isHashtag": false,
  "tweetVolume": null,
  "searchUrl": "https://x.com/search?q=Russell%20Brand",
  "previousRank": 2,
  "isNewEntry": false,
  "firstSeenAt": "2026-11-05T15:16:05Z",
  "lastSeenAt": "2026-11-05T20:27:24Z",
  "durationHours": 5.2,
  "snapshotsInTop": 7,
  "bestRank": 1,
  "bestRankAt": "2026-11-05T15:16:05Z",
  "startedBeforeWindow": false,
  "windowStart": "2026-11-05T04:04:07Z",
  "source": "trends24"
}
```

Fields: `location`, `locationSlug`, `locationType` (worldwide, country, city), `country`, `snapshotAt` (UTC), `rank` (1-50), `name`, `isHashtag`, `tweetVolume`, `searchUrl` (X search for the topic), `previousRank`, `isNewEntry`, `firstSeenAt`, `lastSeenAt`, `durationHours`, `snapshotsInTop`, `bestRank`, `bestRankAt`, `startedBeforeWindow` (already listed in the oldest snapshot, so it may have started earlier), `windowStart`, `source`, `url`, `scrapedAt`.

Topics are the public trend labels X shows. No tweets, authors or user profiles are collected.

### Input

| Field | Meaning | Default |
|---|---|---|
| `locations` | Location names, `City, Country`, trends24 slugs (`united-states/new-york`) or trends24 links. `worldwide` for global trends | worldwide, United States |
| `hoursBack` | 0 = the latest snapshot only; 1 to 24 = every snapshot of that many past hours | 0 |
| `topN` | Ranks per snapshot, 1 to 50 | 50 |
| `useFallback` | Read getdaytrends.com when trends24 refuses a country or worldwide | true |
| `maxItems` | Stop after this many rows in total | 200 |
| `mode` | `scrape`, or `monitor` for new topics only | `scrape` |

A city name that exists in two countries (Birmingham) needs the country: `Birmingham, United Kingdom`. Unknown or ambiguous locations are skipped with a warning in the log.

### Monitor mode

Set `mode` to `monitor` and schedule the task, for example every hour. The first run records each location's current top 50 (no rows, no result charges). Every later run returns only topics that are in that location's top N now and were not anywhere in its top 50 on any run during the last day. So a topic climbing from #11 into the top 10 is not new, a topic that drops out and comes back within a day is not reported twice, and a weekly topic such as "Good Thursday" is reported again the next week. Rank moves inside the list are not reported. Each run reads the latest snapshot (or the getdaytrends fallback) and compares the whole top 50. `hoursBack` is ignored in this mode. Each monitor run costs one `monitor-check` event ($0.005) plus $0.001 per new topic.

If a monitor run crashes, the next run of the same task waits until the crashed run's timeout before it reads again (it ends as `overlapping_run` without charges). Give the task a new `monitorStateId` to start over at once.

### Pricing

| Event | Price |
|---|---|
| result | $0.001 per row ($1 per 1,000) |
| monitor-check | $0.005 per monitor run |
| change | $0.001 per new topic in monitor mode |

Apify platform usage is billed to you separately; the actor runs without a proxy on 512 MB, so it is small. A run that finds nothing pushes nothing and costs no result events.

### Limits

- History depth is what trends24 keeps: 24 snapshot cards per location, 17 to 24 hours on 05.11.2026. Cards posted seconds apart are merged into one snapshot, so a full page gives 20 to 24 distinct hours. `firstSeenAt` and `durationHours` are measured inside that window; `startedBeforeWindow: true` marks topics that were already trending at its start.
- Snapshot times are trends24's own, about an hour apart but not on the hour.
- `tweetVolume` is empty while X hides counts.
- The getdaytrends fallback covers worldwide and countries, not cities, and has no history fields.

### FAQ

**Can I use WOEID numbers?** Not yet. Use the location name or the trends24 slug; the 467 locations are the same set X publishes trends for.

**How do I get trends every hour?** Schedule a task hourly with `hoursBack: 0`, or once a day with `hoursBack: 24`.

### Changelog

- 0.1: first release. Several locations per run, hourly snapshots of the last 24 hours, first-seen time, duration, best and previous rank, getdaytrends fallback, monitor mode for new topics.

### Related actors

- [Google Trends Scraper](https://apify.com/datahamster/google-trends-scraper): search interest and rising queries.
- [Google News Feed](https://apify.com/datahamster/google-news-feed): news headlines by keyword or topic.
- [Reddit Scraper](https://apify.com/datahamster/reddit-scraper): posts from subreddits and searches.
- [Bluesky Scraper](https://apify.com/datahamster/bluesky-scraper): posts from Bluesky search and profiles.

***

If this actor saved you time, a short review on its Store page helps other people find it. Found a bug or need a field? Open a ticket on the **Issues** tab.

# Actor input Schema

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

Stop after this many rows in total across all locations and snapshots (you are charged only for pushed rows).

## `mode` (type: `string`):

scrape = full results; monitor = only new/changed items since the previous run of this task

## `monitorStateId` (type: `string`):

Optional state id when not running as a saved task (monitor mode)

## `webhookUrl` (type: `string`):

POST a change summary here in monitor mode

## `telegramBotToken` (type: `string`):

Optional: bot token for monitor-mode change summaries

## `telegramChatId` (type: `string`):

Optional: chat id that receives monitor-mode summaries

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

Where to read trends: "worldwide", a country ("Japan"), a city ("New York" or "London, United Kingdom"), a trends24 slug ("united-states/new-york") or a trends24.in link, one per line. 467 locations: worldwide, 62 countries, 404 cities.

## `hoursBack` (type: `integer`):

0 = only the latest top 50. 1 to 24 = every hourly snapshot from that many past hours (trends24 keeps 24 snapshots per location). Ignored in monitor mode.

## `topN` (type: `integer`):

How many ranks to return from each snapshot, e.g. 10 for the top 10. In monitor mode, a topic is new when it enters this top N without having been in the top 50 during the last day.

## `useFallback` (type: `boolean`):

When trends24.in refuses a worldwide or country page, read the current top 50 from getdaytrends.com (no history fields, no cities).

## Actor input object example

```json
{
  "maxItems": 20,
  "mode": "scrape",
  "locations": [
    "worldwide",
    "United States"
  ],
  "hoursBack": 0,
  "topN": 10,
  "useFallback": true
}
```

# Actor output Schema

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

All pushed rows (dataset, JSON)

## `resultsTable` (type: `string`):

Dataset in the Console viewer

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

RUN_SUMMARY record

# 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 = {
    "maxItems": 20,
    "locations": [
        "worldwide",
        "United States"
    ],
    "hoursBack": 0,
    "topN": 10
};

// Run the Actor and wait for it to finish
const run = await client.actor("datahamster/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 = {
    "maxItems": 20,
    "locations": [
        "worldwide",
        "United States",
    ],
    "hoursBack": 0,
    "topN": 10,
}

# Run the Actor and wait for it to finish
run = client.actor("datahamster/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 '{
  "maxItems": 20,
  "locations": [
    "worldwide",
    "United States"
  ],
  "hoursBack": 0,
  "topN": 10
}' |
apify call datahamster/twitter-trends-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,datahamster/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/9s5KLO7BugCCbrg1K/builds/tQ5SGis2dcerDCEV2/openapi.json
