---
title: "How to get X (Twitter) data"
description: "Get X posts with view counts, profiles and account timelines as JSON in the X API v2 shape, without a developer account. X’s 2026 pay-per-use prices, working code and costs."
canonical_url: https://groundsocial.dev/guides/how-to-get-x-twitter-data
---
# How to get X (Twitter) data

> Get X posts with view counts, profiles and account timelines as JSON in the X API v2 shape, without a developer account. X’s 2026 pay-per-use prices, working code and costs.

_Checked 2026-11-27._

X’s API is pay-per-use with no free plan: $0.005 for every post you read, so $0.10 for a page of 20. A data API that reads what X shows logged-out visitors returns an account’s latest posts with views, likes and media in the X API v2 shape, 1 credit a page.

> **Checked 27 November 2026** Every request on this page was run against the live API on that date, and the sample response is from that run. Official-API facts link to the platform’s own pages.

## The official X API

X sells API access per resource read, from prepaid credits:

- **$0.005 per post read** and **$0.010 per user read**; writes cost more ($0.015 a post, $0.200 with a URL).
- Pay-per-use is capped at 3 million post reads a month; above that you need an Enterprise contract with unpublished prices.
- The legacy Basic and Pro plans moved to pay-per-use in 2026. You need a developer account, an app and a saved card before the first call.

Sources: [X API pricing](https://docs.x.com/x-api/getting-started/pricing), [X API rate limits](https://docs.x.com/x-api/fundamentals/rate-limits).

## Quick start

1. **Get a key.** [Sign up](https://groundsocial.dev/app/sign-in?new=1) with an email code: 100 free credits, no card. An agent can sign itself up with `POST https://api.groundsocial.dev/v1/agent/signup`.
2. **Set it in your shell.** `export GROUNDSOCIAL_API_KEY=gs_live_…`
3. **Make the call.** An account’s latest posts: `GET /v1/x/users/NASA/tweets`, 1 credit.

cURL:

```bash
curl "https://api.groundsocial.dev/v1/x/users/NASA/tweets" \
  -H "Authorization: Bearer $GROUNDSOCIAL_API_KEY"
```

TypeScript:

```ts
const res = await fetch('https://api.groundsocial.dev/v1/x/users/NASA/tweets', {
  headers: { Authorization: `Bearer ${process.env.GROUNDSOCIAL_API_KEY}` },
})
if (!res.ok) throw new Error((await res.json()).error.hint)
const data = await res.json()
```

Python:

```python
import 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()
```

## Sample response

Trimmed from the real response on 27 November 2026: lists cut to their first items and long strings shortened. Every field is described in the [tutorial](https://groundsocial.dev/tutorials/x/user-tweets/python).

```json
{
  "data": [
    {
      "id": "2126050028032872522",
      "text": "RT @astro_anil: From space to Earth: wishing you a happy thanksgiving.  From this vantage…",
      "created_at": "2026-11-26T20:26:41.000Z",
      "author_id": "11348282",
      "conversation_id": "2126050028032872522",
      "lang": "en",
      "source": "Twitter for iPhone",
      "edit_history_tweet_ids": [
        "2126050028032872522"
      ]
    }
  ],
  "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",
        "protected": false
      }
    ],
    "tweets": [
      {
        "id": "2125971502923129200",
        "text": "From space to Earth: wishing you a happy thanksgiving.  From this vantage point there is s…",
        "created_at": "2026-11-26T15:14:39.000Z",
        "author_id": "1456357980216066048",
        "conversation_id": "2125971502923129200",
        "lang": "en",
        "possibly_sensitive": false
      }
    ],
    "media": [
      {
        "type": "video",
        "width": 1080,
        "height": 1920,
        "duration_ms": 108466
      }
    ]
  },
  "meta": {
    "result_count": 20,
    "newest_id": "2126050028032872522",
    "oldest_id": "2123798314843787300",
    "next_token": "11i1jiz63kysz34d",
    "view": "timeline"
  }
}
```

## Get every page

`/v1/x/users/NASA/tweets` returns posts a page at a time, and each page costs 1 credit. Pass the response’s `meta.next_token` back as `after` to `/v1/x/users/NASA/tweets/next` until it runs out.

TypeScript:

```ts
// Collect up to 3 pages of posts.
const first = 'https://api.groundsocial.dev/v1/x/users/NASA/tweets'
const next = 'https://api.groundsocial.dev/v1/x/users/NASA/tweets/next'
const items: unknown[] = []
let cursor: string | undefined
for (let page = 0; page < 3; page++) {
  const url = new URL(cursor ? next : first)
  if (cursor) url.searchParams.set('after', cursor)
  const res = await fetch(url, {
    headers: { Authorization: `Bearer ${process.env.GROUNDSOCIAL_API_KEY}` },
  })
  if (!res.ok) throw new Error((await res.json()).error.hint)
  const data = await res.json()
  items.push(...(data.data ?? []))
  cursor = data.meta?.next_token ?? undefined
  if (!cursor) break
}
console.log(items.length, 'posts')
```

Python:

```python
import os, requests

# Collect up to 3 pages of posts.
FIRST = "https://api.groundsocial.dev/v1/x/users/NASA/tweets"
NEXT = "https://api.groundsocial.dev/v1/x/users/NASA/tweets/next"
headers = {"Authorization": f"Bearer {os.environ['GROUNDSOCIAL_API_KEY']}"}
items, cursor = [], None
for page in range(3):
    params = {"after": cursor} if cursor else {}
    res = requests.get(NEXT if cursor else FIRST, params=params, headers=headers)
    res.raise_for_status()
    data = res.json()
    items += data.get("data") or []
    cursor = (data.get("meta") or {}).get("next_token")
    if not cursor:
        break
print(len(items), "posts")
```

## What else you can get from X

| What you get | Endpoint | Credits |
| --- | --- | --- |
| [An account’s latest posts](https://groundsocial.dev/tutorials/x/user-tweets/python) | `GET /v1/x/users/NASA/tweets` | 1 |
| [A profile with follower counts](https://groundsocial.dev/tutorials/x/user-profile/python) | `GET /v1/x/users/NASA` | 1 |
| [One post with views and top replies](https://groundsocial.dev/tutorials/x/tweet/python) | `GET /v1/x/tweets/1585341984679469056` | 1 |
| [A video post’s transcript](https://groundsocial.dev/tutorials/x/video-transcript/python) | `GET /v1/x/tweets/1585341984679469056/transcript` | 2 |
| [Trending posts](https://groundsocial.dev/tutorials/x/trending-posts/python) | `GET /v1/x/trends/tweets` | 1 |

Each row links to its tutorial. Every X endpoint and price: [X API](https://groundsocial.dev/x-api).

## Tips

- Field names follow the X API v2 (`data`, `includes.users`, `public_metrics.impression_count`), so code written for the official API needs few changes.
- Keyword search, full reply threads and follower lists are not switched on yet: those endpoints answer `503 upstream_unavailable` and are never charged.
- To watch an account, keep `meta.newest_id` and treat any post with a higher id as new.

## Use it from Claude or Cursor (MCP)

Every endpoint is also an MCP tool on the remote server `https://api.groundsocial.dev/mcp`. The `?platforms=x` below loads only the X tools. The client signs in with OAuth, or send your key as a Bearer token. Tools used in this guide: `x_user_tweets`, `x_user_get`, `x_tweet_get`, `x_tweet_transcript`, `x_trends_tweets`.

Claude Code:

```bash
claude mcp add --transport http groundsocial "https://api.groundsocial.dev/mcp?platforms=x"
```

Cursor:

```json
{
  "mcpServers": {
    "groundsocial": {
      "url": "https://api.groundsocial.dev/mcp?platforms=x"
    }
  }
}
```

Claude.ai:

```text
Customize → Connectors → + Add → Add custom connector
URL: https://api.groundsocial.dev/mcp?platforms=x
```

> **Then ask** “Get NASA’s latest posts on X and list the five with the most views.”

Setup for ChatGPT, VS Code, Windsurf, n8n and others: [MCP client setup](https://groundsocial.dev/mcp).

## Pricing

Pay per call from prepaid credits; no subscription. 100 free credits cover the examples on this page. Costs below are at the [credit packs](https://groundsocial.dev/pricing)’ highest and lowest rates.

| Job | Credits | Cost |
| --- | --- | --- |
| Latest posts of 1,000 accounts | 1,000 | $1.00 → $0.40 |
| 1,000 single posts with metrics | 1,000 | $1.00 → $0.40 |
| 1,000 profiles | 1,000 | $1.00 → $0.40 |

## FAQ

### How does that compare with X’s own price?

A page of 20 posts is $0.10 on X’s pay-per-use and 1 credit here. X’s API can do things this can’t, such as full-archive search and posting.

### Why do some accounts return only a few posts?

For some accounts X shows logged-out visitors only their latest originals. Then `meta.view` is `recent_originals` and there is no next page.

### Can I post or like?

No. It is read-only.

### Are failed calls charged?

No. A target that does not exist answers `404 target_not_found`, an upstream failure answers `503`, and neither costs anything. Credits never expire.

### Is Groundsocial official?

No. Groundsocial is an independent API that reads what the platform shows a logged-out visitor. X is a trademark of X Corp. We are not affiliated with or endorsed by X Corp.

## Go deeper

- [X tutorials: 11 endpoints in six languages](https://groundsocial.dev/tutorials/x)
- [Is the Twitter (X) API free?](https://groundsocial.dev/answers/is-the-twitter-api-free)
- [How much does the X (Twitter) API cost?](https://groundsocial.dev/answers/how-much-does-the-x-api-cost)
- [What are the X API Basic tier limits?](https://groundsocial.dev/answers/x-api-basic-tier-limits)
- [What are the X API rate limits?](https://groundsocial.dev/answers/x-api-rate-limits)
- [Is there an MCP server for social media data?](https://groundsocial.dev/answers/social-media-mcp-server)
- [X (Twitter) API alternatives](https://groundsocial.dev/alternatives/x-api)
- [Groundsocial vs the X API](https://groundsocial.dev/compare/x-api)
- [X API pricing in 2026](https://groundsocial.dev/blog/x-api-pricing-2026)
- [Social listening API](https://groundsocial.dev/use-cases/social-listening-api)

## Related guides

- [How to get Reddit data](https://groundsocial.dev/guides/how-to-get-reddit-data)
- [How to get Threads data](https://groundsocial.dev/guides/how-to-get-threads-data)

X is a trademark of X Corp. We are not affiliated with or endorsed by X Corp.

_Canonical HTML: https://groundsocial.dev/guides/how-to-get-x-twitter-data_

## Site Navigation

### Global Hub
- [Home](https://groundsocial.dev/index.md)
- [Pricing](https://groundsocial.dev/pricing.md)
- [Endpoints](https://groundsocial.dev/endpoints.md)
- [For agents](https://groundsocial.dev/agents.md)
- [Docs](https://groundsocial.dev/docs.md)
- [Compare](https://groundsocial.dev/compare.md)
- [Blog](https://groundsocial.dev/blog.md)
- [Tutorials](https://groundsocial.dev/tutorials.md)
- [Changelog](https://groundsocial.dev/changelog.md)
- [llms.txt](https://groundsocial.dev/llms.txt)
- [Agent skill](https://groundsocial.dev/SKILL.md)

### On This Topic
- [Groundsocial: Social data in one API call](https://groundsocial.dev/index.md)
- [Pricing](https://groundsocial.dev/pricing.md)
- [Playground](https://groundsocial.dev/playground.md)
- [Use cases](https://groundsocial.dev/use-cases.md)
- [Brand monitoring API](https://groundsocial.dev/use-cases/brand-monitoring-api.md)
- [Social listening API](https://groundsocial.dev/use-cases/social-listening-api.md)
- [Comment scraping API](https://groundsocial.dev/use-cases/comment-scraping-api.md)
- [Influencer discovery API](https://groundsocial.dev/use-cases/influencer-discovery-api.md)
- [Video transcript API](https://groundsocial.dev/use-cases/video-transcript-api.md)
- [Ad library API](https://groundsocial.dev/use-cases/ad-library-api.md)
- [Review monitoring API](https://groundsocial.dev/use-cases/review-monitoring-api.md)
- [Trend detection API](https://groundsocial.dev/use-cases/trend-detection-api.md)
- [Social lead generation API](https://groundsocial.dev/use-cases/lead-generation-api.md)
- [Market research API](https://groundsocial.dev/use-cases/market-research-api.md)

## Structured data

```json
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://groundsocial.dev/"},{"@type":"ListItem","position":2,"name":"Guides","item":"https://groundsocial.dev/guides"},{"@type":"ListItem","position":3,"name":"How to get X (Twitter) data","item":"https://groundsocial.dev/guides/how-to-get-x-twitter-data"}]}
```
