python – 使用Tweepy查找针对特定关键字的热门推文

忍受我,因为我还在学习
Python ..

我希望能够看到特定主题标签的最热门推文.我能够找到热门推文,我能够找到带有特定主题标签的推文,但是在尝试将这两个标签结合起来时我感到很茫然.

import tweepy

CONSUMER_KEY = 'key'
CONSUMER_SECRET = 'secret'
OAUTH_TOKEN = 'key'
OAUTH_TOKEN_SECRET = 'secret'

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

api = tweepy.API(auth)
trends = api.trends_place(1)

search_hashtag = tweepy.Cursor(api.search, q='hashtag').items(5000)

for tweet in search_hashtag:
    print json.dumps(tweet)

print json.dumps(trends, indent=1)

这就是我现在所做的工作..

谢谢!

最佳答案 来自:
https://dev.twitter.com/rest/public/search

It allows queries against the indices of recent or popular Tweets and behaves similarly to, but not exactly like the Search feature available in Twitter mobile or web clients, such as Twitter.com search. The Twitter Search API searches against a sampling of recent Tweets published in the past 7 days.

因此,你几乎已经得到了你想要的东西.这些实际上是特定主题标签/主题的热门推文.

https://dev.twitter.com/rest/reference/get/trends/place只是为了获得特定位置的热门话题,但是根据您的问题,您似乎想要搜索某个特定主题,而不是当前的主题

点赞