X (Twitter) Trends CLI
GitHub: https://github.com/aycvs2/x-trends
Setup
Install twurl (official Twitter CLI):
bash
gem install twurl
Authorize with your X/Twitter credentials:
bash
twurl authorize --consumer-key YOUR_API_KEY --consumer-secret YOUR_API_SECRET
Get Trending Topics
Worldwide trends:
bash
twurl "/1.1/trends/place.json?id=1" | jq '.[0].trends[:10]'
Trends by location (WOEID):
bash
# USA (WOEID: 23424977) twurl "/1.1/trends/place.json?id=23424977" | jq '.[0].trends[:10]' # Russia (WOEID: 23424936) twurl "/1.1/trends/place.json?id=23424936" | jq '.[0].trends[:10]' # UK (WOEID: 23424975) twurl "/1.1/trends/place.json?id=23424975" | jq '.[0].trends[:10]'
Available Locations
Get all available trend locations:
bash
twurl "/1.1/trends/available.json" | jq '.[] | {name, woeid}'
Find closest location by coordinates:
bash
twurl "/1.1/trends/closest.json?lat=55.7558&long=37.6173" | jq '.'
Search Tweets by Trend
Search recent tweets for a trending topic:
bash
twurl "/2/tweets/search/recent?query=%23YourHashtag&max_results=10" | jq '.data'
Search with filters:
bash
# Only tweets with media twurl "/2/tweets/search/recent?query=%23trend%20has:media&max_results=10" | jq '.data' # Only verified accounts twurl "/2/tweets/search/recent?query=%23trend%20is:verified&max_results=10" | jq '.data'
Common WOEIDs
| Location | WOEID |
|---|---|
| Worldwide | 1 |
| USA | 23424977 |
| Russia | 23424936 |
| UK | 23424975 |
| Germany | 23424829 |
| France | 23424819 |
| Japan | 23424856 |
| Brazil | 23424768 |
| India | 23424848 |
| Canada | 23424775 |
Output Format
Trends response includes:
- •
name- trend name/hashtag - •
url- link to search results - •
tweet_volume- number of tweets (if available) - •
promoted_content- whether it's promoted
Notes
- •API rate limits apply (75 requests per 15 min for trends)
- •Some trends may not have tweet_volume data
- •Use
jqfor JSON parsing and filtering - •Trends update approximately every 5 minutes
- •Twitter API v1.1 is used for trends, v2 for search