twitterapi.tweets.quote_tweets module
quote_tweets.py: Implementation of Twitter Quote Tweets lookup endpoint.
“The Quote Tweets lookup endpoint gives the Quote Tweets for a given Tweet ID. This allows developers that build apps and clients to get the Quote Tweets for a Tweet quickly and efficiently. It also makes it easy for researchers to study the full conversation around a Tweet including all its Quote Tweets.” (Source: https://developer.twitter.com/en/docs/twitter-api/tweets/quote-tweets/introduction)
Find the Open API Spec under: https://api.twitter.com/2/openapi.json
Examples
Get quoted Tweets:
import os
import json
os.environ["BEARER_TOKEN"] = "xxxxxxxxxxx"
from sparta.twitterapi.tweets.quote_tweets import get_quote_tweets
tweet_ids = ['1511275800758300675', '1594704992480690178']
for tweet_id in tweet_ids:
async for tweet_response in get_quote_tweets(tweet_id):
print(json.dumps(tweet_response.tweet))
print(json.dumps(tweet_response.includes))
- async sparta.twitterapi.tweets.quote_tweets.get_quote_tweets(id: str, start_time: datetime | None = None, end_time: datetime | None = None, since_id: str | None = None, until_id: str | None = None) AsyncGenerator[TweetResponse, None]
Asynchronously retrieves tweets quoting a specified tweet.
This function queries the Twitter API to find tweets that are quote tweets of 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 supports time-based filtering and pagination.
- Parameters:
id (str) – The ID of the tweet for which to retrieve quote tweets.
start_time (datetime, optional) – The oldest UTC timestamp from which quote tweets will be provided. Inclusive and in second granularity.
end_time (datetime, optional) – The newest UTC timestamp to which quote tweets will be provided. Exclusive and in second granularity.
since_id (str, optional) – Returns quote tweets with an ID greater than this ID.
until_id (str, optional) – Returns quote tweets with an ID less than this ID.
- Yields:
TweetResponse – An object representing a tweet that quotes the specified tweet.
- Raises:
Exception – If an HTTP error occurs that prevents retrieving the quote tweets 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.