# X (Twitter) Trends Scraper - Trending Topics by Country & City (`topapi/x-trends-scraper`) Actor

Scrape X (Twitter) trending topics and hashtags for 467 places: worldwide, 62 countries, 400+ cities. The current top 50, the hourly timeline, rank change, history by date and hour, top lists. No X account, no login, no cookies. $0.09 per 1,000 trends.

- **URL**: https://apify.com/topapi/x-trends-scraper.md
- **Developed by:** [Top Api](https://apify.com/topapi) (community)
- **Categories:** Social media, Marketing, News
- **Features:** Limited permissions
- **Stats:** 3 total users, 2 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.09 / 1,000 trends

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

### What does X (Twitter) Trends Scraper do?

**X (Twitter) Trends Scraper** collects the trending topics and hashtags on X for any of the **467 places X publishes trends for**: worldwide, 62 countries and 400+ cities. Each trend comes back as one row with its rank, its X search link, its place (with WOEID and country code) and the time of the list. Every row also says how the trend is moving: its rank in the list before, whether it is new, its best rank and how many hours it has been trending, and in which of your other places it trends too. The lists are read from the two public X trend trackers, [trends24.in](https://trends24.in) and [getdaytrends.com](https://getdaytrends.com), and every row names the site it came from (`source`, `sourceUrl`).

Also known as: Twitter trends API · X trending topics scraper · trending hashtags by country · Twitter trends by city · WOEID trends · trends24 scraper · getdaytrends scraper

- **The list now, the hourly timeline or a past date**: the current top 50, every hourly list of about the last 20 hours, picked periods (1, 3, 6, 12, 24 hours, 2 and 3 days ago), N hours ago, or any hour of a past day for worldwide back to 2024-05-15.
- **Rank movement on every row**: `previousRank`, `rankChange`, `isNew`, `bestRank24h`, `hoursTrending24h`, `firstSeenAt` and the full `rankHistory`.
- **Spread across places**: `locationCount`, `locationsTrendingIn` and `bestRankAcrossLocations` over the places of your run.
- **Every place in one run**: type `all`, `all countries`, `all cities` or `all in Japan`.
- **Top lists**: longest trending and most tweeted, for the day, the week or the month.
- **Trend records (add-on)**: a trend's best rank ever and when, and the places it trends in now and before.
- **Monitor mode** for hourly schedules: only trends not delivered for that place in the last 24 hours (`monitorWindowHours`).
- **No X account, no login, no cookies, no API key**: the actor reads only trends24.in and getdaytrends.com, never X itself.

### What data can you get from X trends?

<table>
<tr><td>🔢 Rank (`rank`)</td><td>🏷️ Trend text (`name`), hashtag / cashtag / phrase</td><td>🔗 X search link (`url`, `query`)</td></tr>
<tr><td>🌍 Place, country, country code</td><td>🗺️ WOEID and parent WOEID</td><td>🏙️ Place type (worldwide, country, town)</td></tr>
<tr><td>🕒 List time (`snapshotAt`), age (`hoursAgo`)</td><td>⬆️ Rank before, change, new flag</td><td>🏆 Best rank, hours trending, first / last seen</td></tr>
<tr><td>📈 Rank history, list by list</td><td>📍 Places it trends in, best rank there</td><td>💬 Post count (history before Jan 2026)</td></tr>
<tr><td>⏳ Longest trending (total hours)</td><td>🔥 Most tweeted (score)</td><td>📚 Trend record: best rank ever + places</td></tr>
</table>

Measured on a run over all 467 places (2026-11-06): 21,937 trends from 448 places (19 towns had no list that hour). Rank, name, query, link, trend type, place, WOEID, list time, best rank, hours trending, first and last seen, rank history and spread across places were filled on 100% of rows; country and country code on 99% (worldwide has none); `previousRank` and `rankChange` on 87% (the other 13% are trends that were new to the list, `isNew: true`).

### How to scrape X trends with X (Twitter) Trends Scraper

1. [Create a free Apify account](https://console.apify.com/sign-up). It comes with $5 of monthly credit and no card is needed.
2. Open **X (Twitter) Trends Scraper** and click **Try for free**.
3. Type the places into **Places**: `United States`, `New York, US`, `JP`, `23424977`, `worldwide` or `all`.
4. Pick the hours you want under **Which hours** (empty = the list now) and the filters you need.
5. Click **Start**. The current lists of the United States and worldwide (100 trends) took 2-5 seconds on our test runs.
6. Open the **Storage** tab and **Export** as JSON, CSV or Excel, or connect a schedule.

### ⬇️ Input

| Parameter | Type | Description |
|---|---|---|
| **🔍 What to scrape** | | |
| `locations` | array | Places, one per line: country or town names, `Town, Country`, two-letter codes, WOEIDs, trends24 / getdaytrends links, or `all` / `all countries` / `all cities` / `all in <country>`. Empty = worldwide and the United States. |
| `woeids` | array | Yahoo Where On Earth IDs, as X uses them (1 = worldwide, 23424977 = United States). |
| `listLocations` | boolean | Return the 467 places instead of trends. Default `false`. |
| `listCountry` / `listPlaceType` / `nameContains` | string | Filter the place list by country, type (country, town, worldwide) or name. |
| **🎯 Which hours** | | |
| `includeHistory` | boolean | Every hourly list trends24 keeps for the place (about 20 lists, ~1,000 rows a place). Default `false`. |
| `timePeriods` | array | `live`, `1h`, `3h`, `6h`, `12h`, `24h`, `2d`, `3d`. |
| `hoursAgo` | integer | The one list from N hours ago (0-23). |
| `date` + `hour` | string + integer | A past day (UTC), with an hour for one list or without for all 24. Also `yesterday`, `3 days ago`. |
| `from` / `to` / `every` | string | A range of lists, one per step (`1h`, `6h`, `1d`). |
| `queries` | array | Many lookups in one run: `[{"location": "worldwide", "date": "2025-01-01", "hour": 12}]`. |
| **✂️ Refine results** | | |
| `maxTrendsPerLocation` | integer | Top N of each list, 1-50. Default 50. |
| `excludeHashtags` / `onlyHashtags` | boolean | Drop #hashtags, or keep only them. |
| `includeKeywords` / `excludeKeywords` | array | Keep trends containing one of these words, or drop them. |
| `dedupeTrends` | boolean | With several lists: one row per trend per place (the newest). |
| `readAllTowns` | boolean | With keyword or hashtag filters, towns are skipped when their country's own list has no match. Turn on to read every town. Default `false`. |
| **➕ Extra data** | | |
| `trendDetails` | boolean | The trend record add-on, $0.001 per trend name. Default `false`. |
| `maxTrendDetails` | integer | Cap on trend records per run. Default 50. |
| `topLists` | array | `longest-day`, `longest-week`, `longest-month`, `tweeted-day`, `tweeted-week`, `tweeted-month` (countries and worldwide). |
| **🔁 Monitoring** | | |
| `monitorMode` | boolean | Only trends not delivered for that place by earlier runs. Default `false`. |
| `monitorWindowHours` | integer | A trend delivered within this many hours is not delivered again. Default 24. |
| `monitorStoreName` / `resetMonitor` | string / boolean | The store that remembers deliveries; start over. |
| **📦 Output** | | |
| `maxItems` | integer | Cap on rows for the whole run. Empty = no cap. |
| `constantFields` | object | Columns added to every row, e.g. `{"campaign": "q4"}`. |
| **⚙️ Advanced** | | |
| `proxyConfiguration` | object | Not needed normally (see Limits). |
| `maxConcurrency` | integer | Pages read at once. Default 6. |

Field names of other trends actors are accepted as well, so an existing input pastes as it is: `country` (a name, code or the numbers 1-35 of the karamelo form), `live` / `hour1` / `hour3` / `hour6` / `hour12` / `hour24` / `day2` / `day3`, `maxItemsPerTarget`, `getAvailableLocations`, `placeSearchTerms`, `at`, `maxResults`.

#### Input JSON

```json
{
  "locations": ["United States", "New York, US", "worldwide"],
  "timePeriods": ["live", "6h", "24h"],
  "maxTrendsPerLocation": 20,
  "excludeHashtags": false
}
```

#### Write the town with its country when the name is shared

`Valencia` is a town in Spain and in Venezuela; the run takes the first and says so in the log. Write `Valencia, Venezuela` or `Valencia, VE` to pick one. `all in Brazil` returns Brazil and its 15 towns.

#### Pick the source of the hours you need

The current list and the hourly lists of about the last 20 hours come from trends24 for every place, towns included. Older hours come from getdaytrends: countries for the last 23 hours, worldwide by date back to 2024-05-15. getdaytrends does not serve a country's dated history right now (its own server answers HTTP 520), so those hours are named in the run status and log and never charged.

### ⬆️ Output

One row per trend in one list of one place:

```json
{
  "type": "trend",
  "rank": 4,
  "name": "Derrick Henry",
  "url": "https://x.com/search?q=Derrick%20Henry",
  "trendType": "phrase",
  "location": "United States",
  "woeid": 23424977,
  "countryCode": "US",
  "placeType": "Country",
  "snapshotAt": "2026-11-06T05:03:40.939Z",
  "previousRank": 5,
  "rankChange": 1,
  "isNew": false,
  "bestRank24h": 4,
  "hoursTrending24h": 5,
  "firstSeenAt": "2026-11-06T01:36:23.087Z",
  "rankHistory": [null, null, 7, 6, 5, 5, 4],
  "locationCount": 2,
  "locationsTrendingIn": ["United States", "Worldwide"],
  "source": "trends24.in"
}
```

(A real row from the prefill run, shortened: `rankHistory` holds one value per list, 19 on that run.)

A trend record (add-on) sits in `details` on the first row of each trend name:

```json
"details": {
  "allTimeBestRank": 1,
  "allTimeBestRankAt": "2026-10-12T04:00:00.000Z",
  "worldwideRankNow": 2,
  "placesSeenIn": 26,
  "trendingNowIn": [{"location": "United States", "rank": 1}, {"location": "Mexico", "rank": 11}],
  "seenBeforeIn": [{"location": "Nigeria", "lastSeen": "6 hours ago"}]
}
```

#### Fields

| Field | Meaning |
|---|---|
| `type` | `trend`, `topTrend` (a top-list entry) or `location` (list mode) |
| `rank` | Position in the list, 1-50 |
| `name`, `query`, `url` | The trend, its X search query and search link |
| `trendType`, `isHashtag`, `isCashtag` | hashtag, cashtag or phrase |
| `tweetVolume`, `tweetVolumeText` | The post count, where the list carried one: X stopped publishing it in January 2026, so it is on history lists before then (13 of 50 trends on the worldwide list of 2025-01-01 12:00) and null since |
| `location`, `locationSlug`, `woeid`, `parentWoeid`, `country`, `countryCode`, `placeType` | The place |
| `snapshotAt`, `hoursAgo`, `timePeriod` | When the list was captured, its age, the period you asked for |
| `previousRank`, `rankChange`, `isNew` | Rank in the list before (about an hour earlier), the change, new to the list |
| `bestRank24h`, `hoursTrending24h`, `firstSeenAt`, `lastSeenAt` | Over the lists trends24 keeps for the place (about the last 17-20 hours) |
| `rankHistory`, `rankHistoryLists` | Rank in each of those lists, oldest first; getdaytrends rows: the last 8 hours |
| `locationCount`, `locationsTrendingIn`, `bestRankAcrossLocations` | Where else in your run the trend is in the latest list |
| `details`, `detailsCharged` | The trend record add-on |
| `monitorStatus` | Monitor mode: `new`, or `details` for a trend delivered earlier without its trend record and delivered again with it |
| `topList`, `period`, `totalDurationHours`, `score`, `lastSeen` | Top-list rows |
| `trends24Url`, `getdaytrendsUrl`, `historyByDate` | Place rows |
| `source`, `sourceUrl`, `scrapedAt` | Where and when the row was read |

### How can I use X trends data?

- 📰 **Newsrooms**: see what breaks in a country or a city before it reaches the wires, with `isNew` and `rankChange`.
- 📣 **Social media and brand teams**: join trends while they climb, and follow them across markets with `locationsTrendingIn`.
- 📊 **Analysts and researchers**: build an hourly archive by place, or pull worldwide history by date.
- 🤖 **AI agents and content tools**: feed today's trends into writing, ad or alert pipelines through the API or MCP.
- 💹 **Traders**: watch $cashtags trending by country.

### How much does it cost to scrape X trends?

X (Twitter) Trends Scraper charges **$0.09 per 1,000 trends** ($0.00009 each). Place rows (list mode) cost the same. The trend record add-on is $0.001 per trend name. There is no start fee and no monthly rent. Filtered trends, duplicates, trends already delivered in monitor mode, and hours or places the trackers do not serve are not charged.

| Run | Rows | Charge |
|---|---|---|
| One place now | 50 | $0.0045 |
| The United States and worldwide now (the prefill) | 100 | $0.009 |
| One place, every hourly list (~20 lists) | ~1,000 | ~$0.09 |
| All 467 places now | ~22,000 | ~$1.98 |
| The 467 places as rows | 467 | $0.042 |
| 50 trends with their trend records | 50 + 50 | $0.0545 |

Platform usage is included in the price. Set a **maximum charge** on the run to cap the cost: the actor stops at it.

### Integrations, API, scheduling & MCP

X (Twitter) Trends Scraper works with the [Apify API](https://docs.apify.com/api/v2), the Apify [Python](https://docs.apify.com/api/client/python) and [JavaScript](https://docs.apify.com/api/client/js) clients, [Make](https://apify.com/integrations/make), [Zapier](https://apify.com/integrations/zapier), [n8n](https://apify.com/integrations/n8n), Google Sheets, Slack, webhooks and the [Apify MCP server](https://mcp.apify.com) for AI agents.

#### Run it on a schedule

Turn on **Only new trends (monitor)**, name the store, and add an [Apify schedule](https://docs.apify.com/platform/schedules) every hour. Each run returns only the trends that are new to each place's list; a run with nothing new returns 0 rows and charges nothing.

```json
{
  "locations": ["United States", "United Kingdom", "India"],
  "monitorMode": true,
  "monitorStoreName": "trends-hourly",
  "monitorWindowHours": 24
}
```

### More social media scrapers

- [X (Twitter) Profile Scraper](https://apify.com/TopApi/x-profile-scraper): followers, bio and verified badge of the accounts behind a trend.
- [Bluesky Scraper](https://apify.com/TopApi/bluesky-scraper): posts and profiles from Bluesky.
- [TikTok Scraper](https://apify.com/TopApi/tiktok-scraper): videos, hashtags and profiles from TikTok.
- [Instagram Scraper](https://apify.com/TopApi/instagram-scraper): posts and profiles from Instagram.
- [Google Trends Trending Now Scraper](https://apify.com/scrapersdelight/google-trends-trending-now-scraper): what people search for, by country.

All our actors: [apify.com/TopApi](https://apify.com/TopApi).

### Limits & empty runs

- **Lists are about an hour apart.** trends24 captures X's list about every 52 minutes, so the current list can be up to an hour old. It keeps about the last 17-20 hours, around 20 lists a place.
- **Older hours**: countries for the last 23 hours and worldwide by date back to 2024-05-15 (getdaytrends). Towns have no history older than trends24 keeps.
- **Post counts**: X removed them in January 2026; live lists have none.
- **WOEIDs** come from Yahoo's public GeoPlanet data (CC BY 3.0). 17 of the 404 towns have no clear public WOEID and carry none: ask for them by name.
- **Places without a list**: X sometimes publishes no list for a town (19 of 467 on our all-places run). Those are named in the run status and log, not charged.
- **Speed**: all 467 places took 316-457 seconds on three test runs at the default 256 MB (about 80 seconds reading, the rest writing ~22,000 rows). The run uses the platform's own connection first and moves to an Apify datacenter proxy if a site refuses it. Residential is the last step and was never needed in our tests.
- **Keyword and hashtag filters over many places**: worldwide and the countries are read first, then the towns. A country's towns are skipped when the country's own list has no match (turn on **Read every town** to read them). A filtered run reads more places only while what it delivers pays for reading them: once its platform cost passes $0.0003 and 30% of what it has billed, the places left are not read and the status says how many. Ask for fewer places per run to get them.
- If every route is refused, the run ends **FAILED** with the reason and charges nothing. A run that matches nothing ends with a status that says what to change.

### FAQ

#### How many trends can X (Twitter) Trends Scraper collect in one run?

Up to 50 per list. One place with every hourly list is about 1,000 rows (1,050 for Japan, 3 seconds). All 467 places now is about 22,000 rows (5 to 8 minutes on our test runs). Ranges of past hours add 50 per hour.

#### Can X (Twitter) Trends Scraper get trends for a city?

Yes. 404 towns have their own lists, e.g. `New York, US`, `London`, `Tokyo` or `São Paulo`. Turn on **List the places** for all of them with their WOEIDs (450 of the 467 places have a public one).

#### Can I get historical X trends?

Yes. Each place's hourly lists of about the last 20 hours, countries for the last 23 hours, and worldwide for any hour back to 2024-05-15 with **Date** and **Hour**, or **From / To / Every** for a range.

#### Does X (Twitter) Trends Scraper show tweet volume?

Only on history from before January 2026, when X still published post counts. Since then X shows none on its lists and the field is null.

#### Can I schedule X (Twitter) Trends Scraper to track trends every hour?

Yes. Use monitor mode with an hourly Apify schedule: each run returns only the trends that are new to each place.

#### Do I need an X account, cookies or an API key?

No. X (Twitter) Trends Scraper reads the public trend trackers trends24.in and getdaytrends.com. Nothing to log in to.

#### Can I use X (Twitter) Trends Scraper with the Apify API or an MCP server?

Yes. Call it from the API or the Python or JavaScript client. You can also connect the Apify MCP server to Claude, ChatGPT or Cursor and ask for "trending topics in Japan" in plain words.

#### Why did my X (Twitter) Trends Scraper run return no results?

Check the status message. It says whether a place was not recognised, whether the filters removed everything, whether monitor mode found nothing new, or whether the hours you asked for are not served.

#### Your feedback

Found a bug or need a field? Open an issue in the **Issues** tab and we will look at it.

# Actor input Schema

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

Countries, towns, two-letter codes, WOEIDs or trends24 / getdaytrends links, one per line. E.g. "United States", "New York, US", "JP", "23424977", "worldwide".

## `woeids` (type: `array`):

Yahoo Where On Earth IDs, as X uses them. E.g. 1 (worldwide), 23424977 (United States), 2459115 (New York). Turn on "List the places" to see all 467.

## `listLocations` (type: `boolean`):

Return the 467 places X publishes trends for, with WOEID, country code and place type, instead of trends. Filter them with the three fields below.

## `listCountry` (type: `string`):

With "List the places": keep the places in one country. E.g. "Japan" or "JP".

## `listPlaceType` (type: `string`):

With "List the places": keep one kind of place.

## `nameContains` (type: `string`):

With "List the places": keep places whose name contains this text. E.g. "san".

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

All the hourly lists trends24 keeps for the place (about 20 lists of 50, the last ~20 hours, ~1,000 rows per place), instead of the current list only.

## `timePeriods` (type: `array`):

Pick lists by age. Live = the latest list. 2 and 3 days ago come from the dated history (worldwide).

## `hoursAgo` (type: `integer`):

The one list from N hours ago (0 = now, up to 23).

## `date` (type: `string`):

A past day, YYYY-MM-DD (or "yesterday", "3 days ago"). With an hour: that hour's list. Without: all 24 hourly lists of the day. Worldwide back to 2024-05-15.

## `hour` (type: `integer`):

With a date: the hour of the list, 0-23 UTC.

## `from` (type: `string`):

Start of a range of lists, e.g. "2026-10-01" or "2026-10-01 06". One list per step, up to "To".

## `to` (type: `string`):

End of the range (left out). Empty = up to now.

## `every` (type: `string`):

Time between two lists of the range: 1h, 6h, 1d... Lists are hourly, so a step under 1 hour reads as 1 hour.

## `queries` (type: `array`):

Many lookups in one run, each its own place and hour. E.g. \[{"location": "worldwide", "date": "2025-01-01", "hour": 12}].

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

Top N of each list, 1-50 (X's list is 50 long).

## `excludeHashtags` (type: `boolean`):

Keep only phrase trends, drop #hashtags.

## `onlyHashtags` (type: `boolean`):

Keep only #hashtags.

## `includeKeywords` (type: `array`):

Keep a trend only if its text contains one of these words (case-insensitive). E.g. "election", "#nba".

## `excludeKeywords` (type: `array`):

Drop trends whose text contains any of these words.

## `dedupeTrends` (type: `boolean`):

With several lists (history, periods, dates): keep only the newest row of each trend in each place.

## `readAllTowns` (type: `boolean`):

With keyword or hashtag filters, towns of a country whose own list has no match are skipped (cheaper, fewer empty pages). Turn on to read every town anyway.

## `trendDetails` (type: `boolean`):

Add each trend's all-time record: best rank and when, the places it trends in now (with rank) and before. $0.001 per trend, once per trend name per run.

## `maxTrendDetails` (type: `integer`):

Cap on trend records per run (the add-on).

## `topLists` (type: `array`):

Add getdaytrends' top lists for each country or worldwide: longest trending and most tweeted, for the day, the week or the month.

## `monitorMode` (type: `boolean`):

Return only trends not delivered for that place by earlier runs in the window below (with the 24-hour history: only lists newer than the last run's).

## `monitorWindowHours` (type: `integer`):

A trend delivered within this many hours is not delivered again for the same place.

## `monitorStoreName` (type: `string`):

Named key-value store that remembers what was delivered. Use one per schedule.

## `resetMonitor` (type: `boolean`):

Forget what earlier runs delivered and start over.

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

Cap on rows for the whole run (trends + places). 0 or empty = no cap (all 467 places now = 23,350 rows).

## `constantFields` (type: `object`):

Columns added to every row, e.g. {"campaign": "q4"}.

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

The run reads the trackers on the platform's own connection first, then moves to an Apify datacenter and then a residential session only if a site refuses it. Your own proxy replaces the Apify ones.

## `maxConcurrency` (type: `integer`):

Pages read at once.

## Actor input object example

```json
{
  "locations": [
    "United States",
    "worldwide"
  ],
  "listLocations": false,
  "includeHistory": false,
  "every": "1h",
  "maxTrendsPerLocation": 50,
  "excludeHashtags": false,
  "onlyHashtags": false,
  "dedupeTrends": false,
  "readAllTowns": false,
  "trendDetails": false,
  "maxTrendDetails": 50,
  "monitorMode": false,
  "monitorWindowHours": 24,
  "monitorStoreName": "x-trends-monitor",
  "resetMonitor": false,
  "proxyConfiguration": {
    "useApifyProxy": true
  },
  "maxConcurrency": 6
}
```

# Actor output Schema

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

One item per trend in an hourly list (type "trend"), per top-list entry ("topTrend") or per place in list mode ("location").

# 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": [
        "United States",
        "worldwide"
    ],
    "maxTrendsPerLocation": 50
};

// Run the Actor and wait for it to finish
const run = await client.actor("topapi/x-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": [
        "United States",
        "worldwide",
    ],
    "maxTrendsPerLocation": 50,
}

# Run the Actor and wait for it to finish
run = client.actor("topapi/x-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": [
    "United States",
    "worldwide"
  ],
  "maxTrendsPerLocation": 50
}' |
apify call topapi/x-trends-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,topapi/x-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/8FyejD1GqVrTxf004/builds/Jeh10VNDfHSgflNsC/openapi.json
