# How to get a user's posts from X (Twitter) with Python

Pass the username and page with `data.next`, 20 posts a page. Ten pages are 200 posts for 10 calls and $0.02; on X's own pay-per-use API, reading 200 posts is reported at about $1.

Updated 2026-11-22

## Page through the posts

`screen_name` is the handle without @. If you store numeric user IDs, pass `rest_id` instead; IDs this long stay strings so they are not rounded. The cursor in `data.next` goes back unchanged.

[X post list API](https://xtikapi.com/apis/x/posts/list): `GET /v1/x/posts/list`, $0.002 a call

```bash
curl "https://xtikapi.com/v1/x/posts/list?screen_name=NASA" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

```python
import requests

URL = "https://xtikapi.com/v1/x/posts/list"
HEADERS = {"Authorization": "Bearer YOUR_API_KEY"}

params = {"screen_name": "NASA"}
items = []
for _ in range(10):  # one call per page
    for attempt in range(3):  # 5xx errors are not charged: retry
        response = requests.get(URL, params=params, headers=HEADERS, timeout=60)
        if response.status_code < 500:
            break
    response.raise_for_status()
    data = response.json()["data"]
    items += data["items"]
    if not data.get("next"):  # null on the last page
        break
    params.update(data["next"])

print(len(items), "items")
```

```javascript
const URL = "https://xtikapi.com/v1/x/posts/list";
const HEADERS = { Authorization: "Bearer YOUR_API_KEY" };

let params = {"screen_name":"NASA"};
const items = [];
for (let page = 0; page < 10; page++) {
  let response;
  for (let attempt = 0; attempt < 3; attempt++) {
    // 5xx errors are not charged: retry
    response = await fetch(`${URL}?${new URLSearchParams(params)}`, { headers: HEADERS });
    if (response.status < 500) break;
  }
  if (!response.ok) throw new Error(`HTTP ${response.status}`);
  const { data } = await response.json();
  items.push(...data.items);
  if (!data.next) break; // null on the last page
  params = { ...params, ...data.next };
}
console.log(items.length, "items");
```

Recorded response (lists keep the first two items):

```json
{
  "data": {
    "items": [
      {
        "id": "5197244563152330773",
        "text": "Example text",
        "author": {
          "id": "41089034",
          "username": "example_user",
          "name": "Example name",
          "avatar": "https://example.com/image.jpg",
          "followers": 92213506
        },
        "createdAt": "2026-11-18T21:40:00.000Z",
        "likeCount": 1521,
        "commentCount": 63,
        "shareCount": 243,
        "viewCount": 218599,
        "url": "https://example.com/link"
      },
      {
        "id": "5197231336585028234",
        "text": "Example text",
        "author": {
          "id": "41089034",
          "username": "example_user",
          "name": "Example name",
          "avatar": "https://example.com/image.jpg",
          "followers": 92213506
        },
        "createdAt": "2026-11-18T20:47:24.000Z",
        "likeCount": 506,
        "commentCount": 41,
        "shareCount": 53,
        "viewCount": 193300,
        "url": "https://example.com/link"
      }
    ],
    "has_more": true,
    "next": {
      "cursor": "DAAHCgABHXc0…"
    }
  },
  "meta": {
    "request_id": "example",
    "endpoint": "x.posts.list",
    "normalized": true,
    "unavailable": [
      "cover"
    ],
    "billing": {
      "charged": true,
      "amount": 0.002,
      "balance": 4.98
    }
  }
}
```

## What the example costs

| Step | Calls | Price | Subtotal |
| --- | --- | --- | --- |
| Posts, 10 pages of 20 | 10 | $0.002 | $0.02 |
| Total | 10 | | $0.02 |

## Good to know

- A page held 20 posts in our test on 2026-11-22, and page two had no overlap.
- Each post carries likes, replies, reposts and views; posts without media list `cover` in `meta.unavailable`.
- The X comparison is in our answer on X API pricing, with its sources.

## Endpoints

- [X post list API](https://xtikapi.com/apis/x/posts/list): $0.002 a call

## More about X

- [Agent Reach Twitter/X channel stopped working: what changed?](https://xtikapi.com/answers/agent-reach-twitter-channel-broken)
- [twikit errors (Cloudflare 403, KEY_BYTE, login 399, rate limits, bans): how do I fix them?](https://xtikapi.com/answers/twikit-errors-and-fixes)
- [twscrape errors (404, No account available, XClIdParseError, ct0, bans): how do I fix them?](https://xtikapi.com/answers/twscrape-errors-and-fixes)
- [How do I convert an X (Twitter) username to its user ID (rest_id)?](https://xtikapi.com/answers/x-username-to-user-id)
- [Nitter is shutting down: how else can I read X accounts without logging in?](https://xtikapi.com/answers/nitter-shut-down-alternative)
- [snscrape returns blocked (404) for Twitter: what still works?](https://xtikapi.com/answers/snscrape-twitter-not-working)

## Questions

### How much does this cost with XTikAPI?

The example here is 10 calls, $0.02 in total. Failed calls and timeouts are free, and a new account with a verified email gets $0.50 of trial balance.

### Do I need an X developer account?

No. The call reads public posts with an API key from this site, with no developer portal, app review or monthly plan.

---

XTikAPI: one API key for public social media data, prepaid per call. [HTML version](https://xtikapi.com/guides/x-user-posts-python) · [llms.txt](https://xtikapi.com/llms.txt) · [OpenAPI](https://xtikapi.com/openapi.json)
