Twython returns less retweets than retweets shown on tweet

79 Views Asked by At

So I am using Twython to get retweeters of a tweet

 tweet = self.twitter.show_status(id=tweet_id)
 if tweet.get('retweet_count') > 0:
        try:
            retweets = self.twitter.get_retweets(id=tweet.get("id"))
        except TwythonRateLimitError:
            self.twitter, self.Last_Acc_Id = self.switch_accounts(MAX_ACCOUNTS)
            self.get_retweeters(tweet)

        # pprint(f"RETWEETS: {retweets}")
        print(f"RETWEET COUNT: {len(retweets)}")
        screen_name_list = []
        for retweet in retweets:
            # print(retweet)
            # print()
            # print(dir(retweet))
            screen_name = retweet["user"]["screen_name"]
            print(screen_name, f"https://twitter.com/{screen_name}/")
            screen_name_list.append(screen_name)

But it returns only 20 retweets where as the tweet has 350 retweets Tweet

Thanks! :)

1

There are 1 best solutions below

1
ByteAlex On

As per documentation "get_retweets" returns "up to" the first 100 retweeters of a tweet. -> Docs

You can specify the amount of entries per request with a parameter "count=100". Furthermore to iterate through multiple requests you should use a cursor (Twython API Docs).

I confirmed with the library source code that this endpoint is used. -> Library Code

Depending of your usecase you should consider using the Webhook API

If the webhook API does not fit your use case, you should reconsider if you only need the retweet count or the retweeters.

The retweet count can simply be requested via GET statuses/show/:id. Look at "retweeted_count".

This is also available in Twython: show_status.

I hope this helped you! :)