Tweepy get retweeters returning max 100

2019-08-17 19:24发布

问题:

I am using Tweepy for getting all retweeters of a particular tweet. My code is as follows:

for reTweet in api.retweets(<tweet_id>,100):
      print reTweet

I tried to use pagination using tweepy cursor as follows:

for status in tweepy.Cursor(api.retweets, <tweet_id>).items():

But it is showing

raise TweepError('This method does not perform pagination')

How to get all retweeters of a tweet using Tweepy API?

回答1:

If you check the Twitter docs for GET statuses/retweets/:id you will see it says:

Returns a collection of the 100 most recent retweets of the Tweet specified by the id parameter.

And if you check the tweepy code you will see that the function you are using uses that API.

    def retweets(self):
    """ :reference: https://dev.twitter.com/rest/reference/get/statuses/retweets/%3Aid
        :allowed_param:'id', 'count'
    """
    return bind_api(
        api=self,
        path='/statuses/retweets/{id}.json',
        payload_type='status', payload_list=True,
        allowed_param=['id', 'count'],
        require_auth=True
    )

What you could do to get more than the 100 retweets limit, if it's a tweet that is still being retweeted is to call the function several times, as long as you respect the rate limits, and store the unique results from each call.

You won't be able to get the older retweets if the tweet was retweeted more than 100 times before you start tracking it.