使用 tweepy 流式传输用户的时间线和过滤的推文 [英] Using tweepy to stream users' timeline and filtered tweets

查看:48
本文介绍了使用 tweepy 流式传输用户的时间线和过滤的推文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天前我开始探索 tweepy,并且能够实时流式传输过滤的(使用关键字)推文.现在,我不仅要流式传输经过过滤的推文,还要流式传输来自几个特定 twitter 用户的推文.这可以通过使用 tweepy 实现吗?似乎 stream.userstream() 只从我的 twitter 帐户而不是其他特定用户中获取实时推文,对吗?我已经用另一个我为测试而创建的推特帐户进行了尝试,但它根本没有获取我在推特上发布的任何新推文.

I started exploring tweepy a couple days ago and was able to stream filtered (with keywords) tweets at real time. Now I want to stream not only filtered tweets but also tweets from several specific twitter users. Is this possible by using tweepy? It seems stream.userstream() only fetches real-time tweets from my twitter account NOT from other specific users, right? I have tried it with another twitter account that I created for testing but it does not fetch any new tweets that I tweeted, at all.

但如果它有效,我可以同时使用 stream.userstream() 和 stream.filter() 下载推文吗?如果没有,那么我怎样才能同时获得过滤后的推文和用户的实时推文?

But if it works, can I download tweets using stream.userstream() and stream.filter() at the same time? If not then how can I get both filtered tweets and users' real time tweets?

顺便说一句,我使用了@alexhanna 的示例代码.

Btw I used the example code from @alexhanna.

api      = tweepy.API(auth)

def main( mode = 1 ):
follow = []
track  = ['Houston Rockets','Lakers','Chicago Bulls']

listen = SListener(api, 'test')
stream = tweepy.Stream(auth, listen)

try: 
    stream.userstream('NBA','ESPN')
    stream.filter(track = track, follow = follow)

except:
    print "error!"
    stream.disconnect()

非常感谢您的帮助!谢谢.

Would really appreciate your help! Thanks.

推荐答案

事先尝试使用 .filter(follow="") 而无需 .userstream().Userstream 只是来自与您的应用程序关联的帐户的推文.这里是一个(注释很好)的例子.

Try using the .filter(follow="") without .userstream() beforehand. Userstream is only the tweets from the account associated with your application. Here is a (very well-annotated) example.

如果您想同时获取用户的推文和过滤后的推文,您需要制作两个单独的 Stream() 对象.

If you want to get the user's tweets and filtered tweets at the same time you need to make two separate Stream() objects.

编辑:页面 我链接到现在已经死了.Internet Archive 链接应无限期地保持活动状态,但解决用户问题的所有相关信息都已包含在此答案中.我没有从链接页面复制和粘贴示例,因为我不是它的作者,而且因为它只是一个示例,说明了 Stream 侦听器的正确使用.

Edit: the page I linked to is now dead. The Internet Archive link should remain active indefinitely, but all the relevant information to solving the user's question is already contained within this answer. I have not copied and pasted the example from the linked page as I am not the author of it, and because it is only an example that illustrates the proper use of a Stream listener.

这篇关于使用 tweepy 流式传输用户的时间线和过滤的推文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆