# X (Twitter) 用户内容 API (twitter.user_posts)

- Canonical page: https://everyinfra.com/twitter-api/user_posts
- Endpoint: POST https://api.everyinfra.com/api/v1/social with {"platform": "twitter", "action": "user_posts", "params": {...}}
- Price: $0.000556 per call ($0.56 per 1,000 requests); failed calls and empty results are not charged
- Returns: list, default 20, max 200 per call
- Mode: sync; add "mode": "async" for slow tasks

用户推文按 `username` 读取一个账号发的帖子，每条带正文、浏览与互动数、`media`、`hashtags`、`mentions`、`links`，以及作者的粉丝数、发帖总数和注册时间 `author_created_at`。它回答「这个账号在说什么」，适合观察品牌号或意见领袖的发帖节奏，做内容复盘，或抽样看一个圈子聊的话题。

每条里的 `is_quote` 标出引用推文，`is_repost` 标出转发，`conversation_id` 把同一串对话的帖子归在一起。`language` 由平台判定，未必准确，抽样看一个圈子的话题时可以先按它粗分。

## Health

- Live health (24h percent, hourly and daily trends): https://api.everyinfra.com/api/v1/social/availability?platform=twitter&action=user_posts

## Parameters

| name | type | required | default | description |
|---|---|---|---|---|
| username | not declared | yes | not declared | X 用户短名，可带 @，不要填完整主页 URL。profile 从最近帖子内的作者信息整理资料；followers_list 与 following_list 分别读取可见粉丝和关注账号，不保证完整关系网。 |
| limit | integer (1–200) | no | 20 | 这次调用最多返回的条数，整数，1–200；不传按默认值，实际返回可能少于这个数。超过上限会在扣费前返回 422。 |

## Response fields (items in `results`)

| field | meaning |
|---|---|
| id | 该记录在原平台上的唯一标识。仅在同一平台内唯一，跨平台可能重复。 |
| url | 该记录在原平台上的可访问链接。 |
| text | 正文内容，已去除 HTML 标签，全文返回、不截断（个别平台的列表结果本身只有摘要，以该平台的字段说明为准）。 |
| like_count | 点赞数。null 表示该平台或该接口不公开此数据，不等于 0。 |
| retweet_count | 转发数。 |
| reply_count | 回复数，通常用于评论的子回复。null 表示不公开。 |
| view_count | 浏览/播放数。null 表示不公开，不等于 0。 |
| posted_at | 发布时间，ISO 8601 格式、UTC 时区（如 2026-08-07T12:34:56+00:00）。平台只给非标准字符串时原样透传，解析前建议做容错。null 表示平台未公开。 |
| author_username | 作者用户名（@handle），通常可用于拼 URL。 |
| author_name | 作者昵称（显示名）。 |
| author_url | 作者在原平台的主页链接。 |
| author_follower_count | 作者粉丝数。null 表示不公开。 |
| quote_count | platform-native meaning |
| bookmark_count | 书签（收藏）数。 |
| language | 内容语言代码（如 zh、en），由平台判定，可能不准。 |
| conversation_id | 所属对话串 ID（根推文 ID），同一串的回复据此归在一起。 |
| is_reply | platform-native meaning |
| is_quote | 是否引用推文。 |
| is_repost | platform-native meaning |
| is_pinned | platform-native meaning |
| reply_to_id | platform-native meaning |
| reply_to_user_id | 所回复用户的数字 ID。 |
| reply_to | platform-native meaning |
| source | 发推客户端（如 Twitter for iPhone）；平台没给时没有这个键。 |
| media | 推文图片 / 视频：type（photo / video / animated_gif）、url（图片或视频封面）、width、height、duration_sec（视频秒数）、video_url（码率最高的 mp4）。 |
| hashtags | 正文里的话题标签数组，按出现顺序；没有时不出现这个字段。 |
| mentions | 正文里 @ 到的用户名。 |
| links | 正文里的外链（展开后的完整网址）。 |
| author_id | 作者在原平台的唯一 ID。 |
| author_avatar_url | 作者头像图片链接（多数平台带签名、会过期）。 |
| author_bio | platform-native meaning |
| author_is_verified | platform-native meaning |
| author_following_count | platform-native meaning |
| author_post_count | 作者推文总数。 |
| author_media_count | 作者发过的媒体数。 |
| author_created_at | platform-native meaning |
| author_banner_url | 作者主页横幅图链接。 |
| platform | 数据来源平台标识，与请求里的 platform 一致（如 xiaohongshu、tiktok）。 |

## Example

```bash
curl -X POST 'https://api.everyinfra.com/api/v1/social' \
  -H "Authorization: Bearer $EVERYINFRA_API_KEY" \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "platform": "twitter",
  "action": "user_posts",
  "params": {
    "username": "nasa"
  }
}'
```

```python
import os
import requests

response = requests.post(
    "https://api.everyinfra.com/api/v1/social",
    headers={"Authorization": f"Bearer {os.environ['EVERYINFRA_API_KEY']}"},
    json={
        "platform": "twitter",
        "action": "user_posts",
        "params": {
            "username": "nasa",
        },
    },
    timeout=120,
)
print(response.status_code)
print(response.json())
```

## Response example

Real response to the example request above, captured 2026-09-26T08:56:04Z. `results` and `count` are real with personal information (names, handles, avatars, profile links, contact details) removed; the list keeps the first 2 of 20. `id`, `billing` and `quota` differ on every call, so only their shape is shown.

```text
{
  "id": "req_…",
  "platform": "twitter",
  "action": "user_posts",
  "results": [
    {
      "id": "•••",
      "url": "https://x.com/NASA/status/2103610284464316469",
      "text": "With @•••, we’ll provide an update on Starliner development and plans for regular crew flights to and from the @••• Watch live Monday, Sept. 28 at 3pm ET: https://t.co/bxg2gpZzog https://t.co/OJaD49OyHh",
      "like_count": 2460,
      "retweet_count": 312,
      "reply_count": 119,
      "view_count": 558723,
      "posted_at": "Fri Sep 25 22:19:09 +0000 2026",
      "author_username": "NASA",
      "author_name": "NASA",
      "author_url": "https://x.com/•••",
      "author_follower_count": 92375074,
      "platform": "twitter"
    },
    {
      "id": "•••",
      "url": "https://x.com/NASA/status/2103589735449141451",
      "text": "@••• 🤭",
      "like_count": 61,
      "retweet_count": 1,
      "reply_count": 7,
      "view_count": 5641,
      "posted_at": "Fri Sep 25 20:57:30 +0000 2026",
      "author_username": "NASA",
      "author_name": "NASA",
      "author_url": "https://x.com/•••",
      "author_follower_count": 92375074,
      "platform": "twitter"
    }
  ],
  "count": 20,
  "billing": {
    "charged": …,
    "charged_usd": …,
    "balance_after_usd": …,
    …
  },
  "quota": { … }
}
```

## FAQ

### 单次最多能读多少条帖子？

默认 20 条，单次最多 200 条。账号发得更多时，一次调用只能拿到其中一部分。需要跨账号按话题找帖子，或者用 from:、since: 这类语法缩小范围，改用关键词搜索那一页。

### `username` 能填主页链接吗？

这一页不能。`username` 填 X 用户短名，带不带 @ 都行，不要填完整主页 URL。手里只有主页链接时，先取出链接里的用户名再填。返回的每条帖子带 `author_username`，通常可以用来拼主页 URL。

### 怎么把原创、引用和转发分开？

先看 `is_quote`，为真的是引用推文；再看 `is_repost`，它标出转发。剩下的就是账号自己写的内容，再用 `is_pinned` 找出置顶的那条。统计发帖节奏时，建议先按这几个字段分组，再看 `posted_at` 的分布。每条还自带 `author_follower_count` 和 `author_post_count`，合并几个账号的结果时，直接按账号体量分组，不必再单独查账号资料。

## Also

- Capability catalog (no key): https://api.everyinfra.com/api/v1/social/catalog?platform=twitter
- OpenAPI: https://everyinfra.com/openapi.json · Agents guide: https://everyinfra.com/agents.md
