【问题标题】:How to filter Stream by mentions如何按提及过滤流
【发布时间】:2014-06-05 21:43:45
【问题描述】:

我正在创建一个 Twitter 机器人,它将响应指向其关联 Twitter 句柄的推文。我看过有关如何按主题标签过滤流的文档,但我不知道如何按提及进行过滤。例如,如果与机器人关联的 Twitter 句柄是 twitter_bot,我想做这样的事情:

listener = CustomListener()
stream = tweepy.Stream(OAuth, listener)

# Is there a parameter here that accomplishes this??
stream.filter(mentions=["twitter_bot"])

我只想处理有人在 twitter_bot 句柄上发推文的情况。

即。 “@twitter_bot 进展如何?”

谢谢!

【问题讨论】:

标签: python tweepy twitter-streaming-api


【解决方案1】:

有一个 REST API endpoint 用于提及,您可以将它与 tweepy 一起使用,documentation 已过时,该方法已重命名为mentions_timeline。这里有 tweepy 中的方法:https://github.com/tweepy/tweepy/blob/master/tweepy/api.py#L79

使用以下代码并更改密钥/秘密,您将获得经过身份验证的用户的提及:

import tweepy

auth = tweepy.OAuthHandler(consumer_key='AAA', consumer_secret='BBB')
auth.set_access_token('CCC', 'DDD')
api = tweepy.API(auth_handler=auth, secure=True, retry_count=5)

mentions = api.mentions_timeline()
for mention in mentions:
    print mention.id, mention.author.screen_name, mention.text

【讨论】:

    猜你喜欢
    • 2017-08-06
    • 1970-01-01
    • 2019-08-30
    • 1970-01-01
    • 2018-01-31
    • 1970-01-01
    • 2016-01-25
    • 2020-05-01
    • 1970-01-01
    相关资源
    最近更新 更多