# Twitter API get user tweets: X's price and how far back

> X's user timeline returns up to 3,200 recent posts at $0.005 each. Ours needs no X account, costs 5 credits per 20 posts and ends near 2,000 posts.

- URL: https://toolzerhub.com/blog/twitter-api-get-user-tweets
- Published: 2026-10-17
- Publisher: ToolzerHub (we sell the API this post describes)

## Short answer

- X's API gets a user's tweets from GET /2/users/{id}/tweets: 5 to 100 posts a request, the 3,200 most recent, at $0.005 per post read, so 1,000 posts cost $5.00.
- ToolzerHub's /v1/x/profile/posts takes a handle and returns 20 posts for 5 credits, with no X developer account. Four accounts ended at 2,035 to 2,065 posts.
- A later page sometimes comes back empty before the real end, so the script below asks the same cursor again. For older posts, search with from: and month windows.

X's API returns a user's tweets from `GET /2/users/{id}/tweets`, up to the 3,200 most recent, at $0.005 per post read. ToolzerHub's `/v1/x/profile/posts` takes a handle, needs no X developer account, and costs 5 credits per 20 posts. It ends at about 2,000 to 2,100 posts per account, and a later page can come back empty before the real end.

## How X's API gets a user's tweets

X's [user timeline](https://docs.x.com/x-api/posts/timelines/introduction) returns the most recent posts by one account, up to 3,200, with filters for replies, retweets and time. It takes the account's numeric ID, not its handle, returns 5 to 100 posts a request, and needs an approved developer account with a Project and App. X bills $0.005 per post read and $0.010 for the user lookup that turns a handle into an ID; repeats within a day are charged once, and reading your own account costs $0.001 per post.

X's API is the better pick when you need the 3,200-post depth, filters by time and post type, your own account's posts, or the supported route to post, like or repost. Ours reads public accounts only.

## Get a user's posts with ToolzerHub

We make ToolzerHub. Our [X API](https://toolzerhub.com/apis/x) returns an account's posts by handle, with one API key. `GET /v1/x/profile/posts` takes `handle`, `include_replies` and `cursor`, returns 20 posts newest first plus the pinned post, and costs 5 credits a call. Each post has its text, `created_at`, likes, replies, reposts, quotes, views and bookmarks.

This script writes each account's posts to CSV and marks each row as a post, reply, repost or quote. It leaves out the separate pinned-post field. Pass `yes` as the third argument to include replies. A later page can come back empty before the real end, so the script asks that cursor again, up to twice, before it counts the account as finished.

```python
import csv
import os
import sys
import time

import requests

URL = "https://api.toolzerhub.com/v1/x/profile/posts"
HEADERS = {"x-api-key": os.environ.get("TOOLZERHUB_API_KEY", "")}
FIELDS = ["account", "id", "url", "created_at", "type", "likes", "replies", "reposts",
          "quotes", "views", "bookmarks", "text"]
calls = 0


def cell(value):
    # Spreadsheets run text starting with = + - or @ as a formula; an apostrophe keeps it text.
    if isinstance(value, str) and value[:1] in ("=", "+", "-", "@", "\t"):
        return "'" + value
    return value


def get(params, tries=4):
    # 429 and 503 are retried; the wait comes from the error body or the Retry-After header.
    global calls
    for attempt in range(tries):
        r = requests.get(URL, headers=HEADERS, params=params, timeout=90)
        calls += 1
        if r.status_code == 400:  # malformed handle: skip this account
            print("bad request:", str(r.json()["error"].get("message")).split("\n")[0])
            return None
        if r.status_code not in (429, 503) or attempt == tries - 1:
            if r.status_code >= 500:  # any 5xx, or a 503 past the retries: skip
                print(f"HTTP {r.status_code}, skipping:", r.text[:120].replace("\n", " "))
                return None
            r.raise_for_status()
            return r.json().get("data")
        try:
            wait = r.json()["error"]["details"]["retryAfter"]
        except (ValueError, KeyError, TypeError):
            wait = None
        try:
            wait = int(wait or r.headers.get("Retry-After") or 5 * (attempt + 1))
        except ValueError:
            wait = 5 * (attempt + 1)
        time.sleep(min(wait, 60))


def kind(post):
    if post.get("reposted_post"):
        return "repost"
    if post.get("is_reply"):
        return "reply"
    return "quote" if post.get("quoted_post") else "post"


def export_account(writer, account, max_pages, replies):
    params, seen, pages, empty = {"handle": account}, set(), 0, 0
    if replies:
        params["include_replies"] = "true"
    status = "page cap reached, more available"
    while pages < max_pages:
        data = get(params)
        if data is None:
            status = "stopped early: failed page" if pages else "nothing returned"
            break
        posts = data.get("posts") or []
        if not posts and pages and empty < 2:  # a later page can come back empty once: re-ask it
            empty += 1
            time.sleep(2)
            continue
        empty = 0
        if not posts:
            status = "end" if pages else "nothing returned"
            break
        pages += 1
        for p in posts:
            if not p.get("id") or p["id"] in seen:  # keep one row per post
                continue
            seen.add(p["id"])
            writer.writerow({
                "account": account, "id": p["id"], "url": p.get("url"),
                "created_at": p.get("created_at"), "type": kind(p),
                "likes": p.get("like_count"), "replies": p.get("reply_count"),
                "reposts": p.get("repost_count"), "quotes": p.get("quote_count"),
                "views": p.get("view_count"), "bookmarks": p.get("bookmark_count"),
                "text": cell((p.get("text") or "").replace("\r", " ").replace("\n", " ")),
            })
        if not (data.get("has_more") and data.get("cursor")):
            status = "end"
            break
        params["cursor"] = data["cursor"]
        time.sleep(0.3)
    print(f"{account}: {len(seen)} posts, {pages} pages ({status})")
    return len(seen)


def main(accounts, max_pages="120", replies="no", out="x_posts.csv"):
    total = 0
    with open(out, "w", newline="", encoding="utf-8-sig") as f:  # BOM: Excel reads emoji
        writer = csv.DictWriter(f, fieldnames=FIELDS)
        writer.writeheader()
        for account in [a.strip().lstrip("@") for a in accounts.split(",") if a.strip()]:
            total += export_account(writer, account, int(max_pages), replies == "yes")
    print(f"wrote {total} posts to {out} in {calls} calls")


if __name__ == "__main__":
    if len(sys.argv) < 2 or (len(sys.argv) > 3 and sys.argv[3] not in ("yes", "no")):
        sys.exit("usage: python x_user_posts.py nasa,spacex [max_pages] [yes|no replies] [file.csv]")
    if not HEADERS["x-api-key"]:
        sys.exit("set TOOLZERHUB_API_KEY first")
    main(*sys.argv[1:])
```
The default page cap is 120, so pass a higher cap, as below, for accounts that run to 121 pages.

## Run it

```bash
export TOOLZERHUB_API_KEY=your_key
python x_user_posts.py spacex,duolingo 150 no x_posts.csv
```

Output:

```text
spacex: 2110 posts, 124 pages (end)
duolingo: 2047 posts, 109 pages (end)
wrote 4157 posts to x_posts.csv in 243 calls
```

The tail is thin: SpaceX's last 110 posts stretch back to 2022 and Duolingo's last 47 go back to 2012. Posts from before mid-December 2022 have no view count: 1,155 of the 4,157 rows.

## What the four accounts showed

All four accounts ended near 2,000 posts. We paged each until `has_more` was false, re-asking each empty page up to three times.

| Account | Posts | Oldest returned | Pages |
|---|---:|---|---:|
| SpaceX | 2,036 | 2023-11-11 | 109 |
| NASA | 2,035 | 2022-08-19 | 114 |
| Duolingo | 2,044 | 2012-06-15 | 110 |
| Netflix | 2,065 | 2025-11-22 | 121 |

- The end sits near 2,000 posts, not at a date. Netflix posts often, so its 2,065 reach back eleven months. The oldest dates come from a thin tail, not full coverage, and the count moves a little between runs: SpaceX gave 2,110 in the script run.
- Reposts count toward the total: 148 of SpaceX's 2,110 rows and 321 of Duolingo's 2,047. The default leaves out replies; `include_replies=true` adds them.
- Most pages held 20 posts, and no post repeated within a run.

For older posts, our [Twitter search post](https://toolzerhub.com/blog/twitter-api-search-tweets) pages `from:NASA` one month at a time back to 2020.

## What it costs

A call of 20 posts is 5 credits, so 1,000 posts are 250 credits when every page is full. The run above made 243 calls, 1,215 credits, for 4,157 posts; the same posts on X's pay-per-use would be $20.79, before the user lookups. You get 100 free credits a month; $19 buys 10,000 credits that never expire, and [plans for higher volume](https://toolzerhub.com/pricing) cover more accounts. Set your key and run the script on your first account.

For followers, see [the followers list post](https://toolzerhub.com/blog/twitter-api-followers-list).

We are not affiliated with X Corp.
