Get to stream tweets from users a user is following using tweepy

為{幸葍}努か 提交于 2021-02-20 04:49:04

问题


I'm using Tweepy Streaming methods to try to get all the tweets from a specific user, both the ones the user created and those coming to his timeline from other users the user is following.

I've tried several combinations, this one, for instance, using the user ID, only gives me the tweets that the user pushes:

    l = StreamListener()
    streamer = tweepy.Stream(auth=auth, listener=l)
    streamer.filter(follow=['3071126254'])

The rest of trials all lead me to constant 406 responses from Twitter:

    l = StreamListener()
    streamer = tweepy.Stream(auth=auth, listener=l)
    streamer.filter(follow=[''])

or

    l = StreamListener()
    streamer = tweepy.Stream(auth=auth, listener=l)
    streamer.filter()

Any idea if this is possible? I could always use the REST API to query for the user timeline and then make sure I'm not storing duplicated tweets...but it looks weird that I can't stream all tweets from a users timeline...

Thanks, Alejandro


回答1:


If anyone runs into the same situation, having a close look at the official Twitter docs, it states:

The with parameter controls the types of messages received. The default for User Streams is with=followings, which gives data about the user and about the user’s followings (accounts which the authenticated user follows). The setting with=user sends only events about the user, and not events about their followings.

Thus, it seems that the correct option is using userstream instead of filter, then, this works:

    l = StreamListener()
    streamer = tweepy.Stream(auth=auth, listener=l)
    streamer.userstream(_with='followings')

Then you'll get notified on the on_data callback method. Hope this helps!



来源:https://stackoverflow.com/questions/28867474/get-to-stream-tweets-from-users-a-user-is-following-using-tweepy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!