【发布时间】:2017-05-10 21:46:44
【问题描述】:
最好通过 Python 中的 Tweepy,我想从 Twitter API 获取给定搜索查询和 WOEID 地点标识符(Yahoo's Where On Earth IDentifier)的热门推文列表。
在我的示例中,我通过 Twitter REST API 的 GET 趋势/位置的 Tweepy 的 API.trends_place(id) 包装器获取 WOEID id 的趋势查询;然后我想为这个地方的每个趋势查询打印最热门的推文(相同的 WOEID)。
目前,我获取趋势查询的推文,但是
- 不在给定的地方;
- 不一定是“热门”推文(与例如“最近”相对)。
如何将这两个限制添加到我的搜索中?
MWE:
import tweepy
from tweepy import OAuthHandler
consumer_key = 'YOUR-CONSUMER-KEY'
consumer_secret = 'YOUR-CONSUMER-SECRET'
access_token = 'YOUR-ACCESS-TOKEN'
access_secret = 'YOUR-ACCESS-SECRET'
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth)
locationid = 23424775 # WOEID for Canada
trendqueries = [trend['query'] for trend in api.trends_place(locationid)[0]['trends']]
for trendquery in trendqueries:
print(api.search(q=trendquery))
我尝试过的:
我可以使用 Tweepy 的 API.search(q, geocode) 按经度/纬度进行搜索,但我没有看到按 WOEID 进行搜索的明显方法。
【问题讨论】:
标签: python twitter geolocation tweepy