twitterapi.users.timeline module
timeline.py: Implementation of User Post Timeline endpoint.
The User Post Timeline endpoint allows developers to retrieve recent Posts, Retweets, replies, and Quote Tweets from a specified user.
Endpoint documentation: https://developer.x.com/en/docs/x-api/tweets/timelines/introduction
Example
import os import json os.environ[“BEARER_TOKEN”] = “xxxxxxxxxxx” from datetime import datetime from sparta.twitterapi.timeline import get_user_timeline_by_id
user_id = “2244994945” start_time = datetime(2021, 6, 1) end_time = datetime(2021, 10, 1) async for tweet_response in get_user_timeline_by_id(user_id, start_time=start_time, end_time=end_time, exclude=[“replies”, “retweets”]):
print(json.dumps(tweet_response.tweet)) print(json.dumps(tweet_response.includes))
)
- async sparta.twitterapi.users.timeline.get_user_timeline_by_id(user_id: str, start_time: datetime | None = None, end_time: datetime | None = None, since_id: str | None = None, until_id: str | None = None, exclude: List[str] | None = None) AsyncGenerator[TweetResponse, None]
Asynchronously retrieves Posts from a user’s timeline.
- Parameters:
user_id (str) – The ID of the user.
start_time (datetime, optional) – Earliest datetime for Posts.
end_time (datetime, optional) – Latest datetime for Posts.
since_id (str, optional) – Returns results with Post ID greater than this ID.
until_id (str, optional) – Returns results with Post ID less than this ID.
exclude (List[str], optional) – Entities to exclude, e.g., [“replies”, “retweets”].
- Yields:
TweetResponse – Individual Posts with associated data and includes.
- Raises:
Exception – If an HTTP error occurs or if request parameters are invalid.