简体   繁体   中英

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

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

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM