twitterapi.tweets.retweets module
retweets.py: Implementation of Twitter retweeted_by endpoint.
“With the Retweets lookup endpoint, you can retrieve a list of accounts that have Retweeted a Tweet. For this endpoint, pagination tokens will be provided for paging through large sets of results in batches of up to 100 users. ” (Source: https://developer.twitter.com/en/docs/twitter-api/tweets/retweets/introduction)
Find the Open API Spec under: https://api.twitter.com/2/openapi.json
Examples
Get User that retweeted a specific tweet:
import os
os.environ["BEARER_TOKEN"] = "xxxxxxxxxxx"
from sparta.twitterapi.tweets.retweets import get_retweets
async for user in get_retweets('1679113508724539393'):
print(user.model_dump_json())
- async sparta.twitterapi.tweets.retweets.get_retweets(id: str) AsyncGenerator[User, None]
Asynchronously retrieves users who have retweeted a specified tweet.
This function queries the Twitter API to find users who have retweeted the tweet corresponding to the given ID. It handles rate limiting using an internal instance of RateLimiter, automatically pausing requests if the rate limit is exceeded. The function also handles pagination automatically if there are more results than can be returned in a single response.
- Parameters:
id (str) – The ID of the tweet for which to retrieve retweeters.
- Yields:
User – An object representing a Twitter user who has retweeted the specified tweet.
- Raises:
Exception – If an HTTP error occurs that prevents retrieving the retweets or if the tweet ID is invalid.
Note
The function automatically handles pagination of results using the ‘next_token’ provided by Twitter’s API response.