Reputation: 89
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?
Upvotes: 0
Views: 3298
Reputation: 1850
You need to use tweepy.Cursor
to use paginaton:
def get_retweeters(tweet_id: int) -> List[int]:
"""
get the list of user_ids who have retweeted the tweet with id=tweet_it
:param tweet_id: id of thetweet to get its retweeters
:return: list of user ids who retweeted the tweeet
"""
result = list() # type: List[int]
for page in tweepy.Cursor(api.retweeters, id=tweet_id, count=500).pages():
result.extend(page)
return result
This works for me, python 3.7.7, tweepy 3.10.0
Upvotes: 1
Reputation: 1819
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.
Upvotes: 3