【问题标题】:How to get most popular tweets without query?如何在没有查询的情况下获得最受欢迎的推文?
【发布时间】:2017-04-16 18:07:20
【问题描述】:

我正在使用 Python API,我想从 Twitter 中检索最流行的推文,而不需要特定的查询。我想要所有流行的推文,而不仅仅是与某个搜索词相关的推文。

api = twitter_connect()

for tweet in tweepy.Cursor(api.search, q='query',result_type='popular').items(5):
    print(tweet.text)

不幸的是,在 Twitter API 中,query 参数是必需的。如何独立于搜索查询获取最受欢迎的推文?

【问题讨论】:

  • 你的问题毫无意义。 如果没有询问哪些推文最受欢迎的查询,我如何才能找出哪些推文最受欢迎?不是一个问题。

标签: python twitter


【解决方案1】:

您可能想尝试 Twitter API trends/place 端点。来自文档:

trends/place 返回特定 WOEID (Yahoo! Where On Earth ID) 的前 50 个热门话题

trends1 = api.trends_place(1) # Global information is available by using 1 as the WOEID .
data = trends1[0]
trends = data['trends']

for trend in trends[0:5]: # Get only the first 5 popular trending tweets
    print trend

输出(例如,在本文发布时):

{u'url': u'http://twitter.com/search?q=%23GagaCoachella', u'query': u'%23GagaCoachella', u'tweet_volume': 83882, u'name': u'#GagaCoachella', u'promoted_content': None}
{u'url': u'http://twitter.com/search?q=%23FallonStylesSNL', u'query': u'%23FallonStylesSNL', u'tweet_volume': 538109, u'name': u'#FallonStylesSNL', u'promoted_content': None}
{u'url': u'http://twitter.com/search?q=%22Happy+Easter%22', u'query': u'%22Happy+Easter%22', u'tweet_volume': 485731, u'name': u'Happy Easter', u'promoted_content': None}
{u'url': u'http://twitter.com/search?q=%23Bug%C3%BCnHay%C4%B1r%C3%87%C4%B1kacak', u'query': u'%23Bug%C3%BCnHay%C4%B1r%C3%87%C4%B1kacak', u'tweet_volume': 25544, u'name': u'#Bug\xfcnHay\u0131r\xc7\u0131kacak', u'promoted_content': None}
{u'url': u'http://twitter.com/search?q=%23JavierDuarte', u'query': u'%23JavierDuarte', u'tweet_volume': 67939, u'name': u'#JavierDuarte', u'promoted_content': None}

有关自定义查询的更多选项,请参阅documentation。

【讨论】:

    猜你喜欢
    • 2012-05-08
    • 1970-01-01
    • 2012-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-20
    • 1970-01-01
    相关资源
    最近更新 更多