我目前正在使用以下代码,这会得到推文,然后将其传递给处理的函数.这不是实时的.
@H_403_2@auth = tweepy.OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_token,access_token_secret)
api = tweepy.API(auth)
mentions = api.mentions_timeline(count=1)
for mention in mentions:
processText()
我也看过流媒体播放器,但我还没有找到一个提供流媒体的方法.
解决方法
您可以使用
@L_301_0@过滤包含@mentions的推文.当您使用跟踪参数过滤流时,请按照您感兴趣的用户名过滤您的跟踪参数中的用户名,如下所示:
@H_403_2@stream.filter(track=['twitterapi'])
这将返回您所有包含字符串“twitterapi”的推文,包括@mentions(即“@twitterapi”).请参阅Twitter Streaming API track
parameter了解如何工作.然后,您可以使用结果JSON只采取实际上对您感兴趣的用户进行@的结果的JSON.结果JSON如下所示:
这很糟糕,但是如果您查看“实体”对象,则会看到“user_mentions”:
@H_403_2@"user_mentions":[{"indices":[19,"id_str":"6253282"}]然后,在“screen_name”下,您会看到“twitterapi”,显示用户@twitterapi是@ referenced.