Twitter Streaming:根据国家/地区获取 Twitter 上的趋势 [英] Twitter Streaming: Get trends on Twitter on the basis of countries
问题描述
我正在使用 tweepy
来获取 Twitter 推文.我想根据我选择的国家/地区获取当前趋势.我的代码如下:
I am using tweepy
to get twitter tweets. I want to get the current trends based on the country of my choice. My code is as follows:
import tweepy
file = open("data.txt", 'r')
authentication = tweepy.OAuthHandler('consumer_key', 'consumer_secret')
authentication.set_access_token('access_token', 'access_secret')
api = tweepy.API(authentication)
trends = api.trends_available()
for trend in trends:
print trend
上面的代码给了我一个国家列表.我想使用列表来检查该国当前的趋势.如何提取这些国家/地区的趋势 hashtags
?
The code above gives me a list of countries. I want to use the list to check the current trends in the country. How do I extract the trending hashtags
for these countries?
我遇到了 this 问题,但没有答案.
I came across this question but it has no answers.
推荐答案
你在这个工作中使用了错误的端点,你必须使用 this 转换为 tweepy api.trends_place(woeid)
并提供本页中描述的 woeid
您还可以从 api.trends_available()
结果中获得.
you are using the wrong endpoint for this job you have to use this which translates to tweepy api.trends_place(woeid)
and provide an woeid
as described in this page which you can get also from api.trends_available()
results.
这篇关于Twitter Streaming:根据国家/地区获取 Twitter 上的趋势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!