X (Twitter) user tweets API
An account’s latest posts and reposts, newest first (about 20), with the authors, quoted posts and media they refer to in includes. meta carries result_count, newest_id, oldest_id and a next_token for the next page.
GET /v1/x/users/{username}/tweets1 credit per callRefunded on failureimport os, requests
res = requests.get(
"https://api.groundsocial.dev/v1/x/users/NASA/tweets",
headers={"Authorization": f"Bearer {os.environ['GROUNDSOCIAL_API_KEY']}"},
)
res.raise_for_status()
data = res.json(){ "data": [ { "id": "2124940993489162256", "text": "Happy Thanksgiving from the @Space_Station! https://t.co/MXpk17AAX6", "created_at": "2026-11-23T18:59:46.000Z", "author_id": "11348282", "conversation_id": "2124940993489162256", "lang": "en", "possibly_sensitive": false, "edit_history_tweet_ids": [ "2124940993489162256" ], "public_metrics": { "like_count": 1980, "retweet_count": 268, "reply_count": 84, "quote_count": 15, "bookmark_count": 90, "impression_count": 340787 }, "entities": { "urls": [ "…" ], "mentions": [ "…" ] }, "…": "1 more fields" }, "… 18 more" ], "includes": { "users": [ { "id": "11348282", "name": "NASA", "username": "NASA", "created_at": "2007-12-19T20:20:32.000Z", "description": "Making the seemingly impossible, possible. ✨", "location": "Pale Blue Dot", "url": "https://t.co/9NkQJKAnuU", "profile_image_url": "https://pbs.twimg.com/profile_images/1321163587679784960/0ZxKlEKB_normal.jpg", "profile_banner_url": "https://pbs.twimg.com/profile_banners/11348282/1788992290", "protected": false, "…": "5 more fields" }, "… 6 more" ], "tweets": [ { "id": "2124265863323045902", "text": "A @SpaceX Dragon splashed down in the Pacific Ocean off the coast of California …", "created_at": "2026-11-21T22:17:03.000Z", "author_id": "1451773004", "conversation_id": "2124265863323045902", "lang": "en", "possibly_sensitive": false, "edit_history_tweet_ids": [ "…" ], "public_metrics": { "…": "6 fields" }, "entities": { "…": "2 fields" }, "…": "1 more fields" }, "… 6 more" ], "media": [ { "media_key": "13_2124940778208215040", "type": "video", "preview_image_url": "https://pbs.twimg.com/media/HX1OkiYWQAAGf8b.jpg", "width": 720, "height": 405, "duration_ms": 165965, "variants": [ "…" ] }, "… 16 more" ] }, "meta": { "result_count": 19, "newest_id": "2124940993489162256", "oldest_id": "2123092972296163443", "view": "timeline" }}Parameters
| Name | Type | Description |
|---|---|---|
usernamepath · required | string | Handle, with or without the @, or a profile URL. Example: NASA. |
sincequery | string | Only posts on or after this time. Reaching an older post ends the walk: YYYY-MM-DD (UTC) or an ISO 8601 timestamp. Example: 2026-11-01. |
untilquery | string | Only posts on or before this time (a date includes that whole UTC day): YYYY-MM-DD (UTC) or an ISO 8601 timestamp. Example: 2026-11-01. |
stop_at_idquery | string | The newest post you already hold (id or URL): the page stops just before it and there is no next page. |
Response fields
200 with a XTimelineResponse, in the shape of X’s API v2 Tweet and User objects.
| Field | Type | Description |
|---|---|---|
data | XTweet[] | |
includes | XIncludes | Objects the response refers to by id, each once: authors, quoted and reposted posts, media, polls. |
meta | XTimelineMeta |
Status codes
| Status | Meaning |
|---|---|
200 | The latest posts, with what they refer to. |
400 | Invalid input. Nothing was charged. |
401 | Missing or invalid API key. |
402 | Not enough credits, a spend cap was reached, or payment is required. |
403 | The target is private, or the account is suspended. |
404 | The post or account does not exist, was deleted, or is suspended. |
429 | Too many requests. Wait for Retry-After seconds. |
503 | X is temporarily unavailable. Retryable; nothing was charged. |
Every error has code, message, hint and retryable. All error codes
Questions
Why do I sometimes get only a few posts?
For some accounts X shows logged-out visitors only their latest few original posts, without reposts. Then meta.view is recent_originals and there is no next page.
How do I get older posts?
Pass meta.next_token as after to the next-page endpoint (beta, 2 credits a page). Tokens last an hour.
X is a trademark of X Corp. We are not affiliated with or endorsed by X Corp.