# X (Twitter) 评论 API (twitter.comments)

- Canonical page: https://everyinfra.com/twitter-api/comments
- Endpoint: POST https://api.everyinfra.com/api/v1/social with {"platform": "twitter", "action": "comments", "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 50 per call
- Mode: sync; add "mode": "async" for slow tasks

推文评论按 `id` 读取一条帖子的回复。每条都是一条完整的帖子记录：正文、点赞、转发、浏览数、回复者的用户名和粉丝数。它回答「读者怎么回应这条帖子」，适合做口碑与情绪抽样、收集产品反馈，或者挑出被大量点赞的回复；`media` 里还有回复附带的图片或视频。

传的是被评论的那条帖子的 ID，不是某条评论的 ID。`id` 填 x.com/用户名/status/ 后面的数字，不要放完整链接。同一个 `id` 在单条内容那一页读帖子本身，在这一页读它的回复。

## Health

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

## Parameters

| name | type | required | default | description |
|---|---|---|---|---|
| id | not declared | yes | not declared | post / comments 的数字帖子 ID，即 x.com/用户名/status/ 后的数字，建议用字符串保存以避免 JavaScript 大整数精度损失；不要把完整 URL 放入 id。 |
| tweet_id | not declared | no | not declared | id 的兼容输入，优先级低于 id，不取消公开必填 id。 |
| limit | integer (1–50) | no | 20 | 这次调用最多返回的条数，整数，1–50；不传按默认值，实际返回可能少于这个数。超过上限会在扣费前返回 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": "comments",
  "params": {
    "id": "2103610284464316469"
  }
}'
```

```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": "comments",
        "params": {
            "id": "2103610284464316469",
        },
    },
    timeout=120,
)
print(response.status_code)
print(response.json())
```

## Response example

Real response to the example request above, captured 2026-10-24T18:28:34Z. `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": "comments",
  "results": [
    {
      "id": "•••",
      "url": "https://x.com/SmellyCatGME/status/2104363945867825157",
      "text": "@••• @••• @••• here comes #buckrogers25centurymeme to join tokenised space 😂🚀💯🔥🥳 \nca: DRgbVreehxzR9AHNGHnuQPNAQDDFvCxjZbcBJRyJfwpK",
      "like_count": 2,
      "retweet_count": 0,
      "reply_count": 1,
      "view_count": 8,
      "posted_at": "2026-09-28T00:13:56+00:00",
      "author_username": "•••",
      "author_name": "•••",
      "author_url": "https://x.com/•••",
      "author_follower_count": 71,
      "quote_count": 0,
      "bookmark_count": 0,
      "language": "et",
      "conversation_id": "2103610284464316469",
      "is_reply": true,
      "is_pinned": false,
      "reply_to_id": "2103610284464316469",
      "reply_to_user_id": "•••",
      "reply_to": "NASA",
      "hashtags": [
        "buckrogers25centurymeme"
      ],
      "mentions": [
        "NASA",
        "BoeingSpace",
        "Space_Station"
      ],
      "author_id": "•••",
      "author_avatar_url": "https://pbs.twimg.com/•••",
      "author_is_verified": false,
      "author_following_count": 551,
      "author_post_count": 153,
      "author_media_count": 37,
      "author_created_at": "2026-09-27T17:40:39+00:00",
      "author_banner_url": "https://pbs.twimg.com/profile_banners/2104264552984530944/1790551488",
      "platform": "twitter"
    },
    {
      "id": "•••",
      "url": "https://x.com/RohanArun/status/2103977186055336023",
      "text": "@••• Hey Super, build a\n\nThis request concerns an update from NASA regarding the Starliner development and its crewed missions to the International Space Station. The update was scheduled to be broadcast live on Monday, September 28th, at 3 PM Eastern Time.\n\nThe associated metric…",
      "like_count": 3,
      "retweet_count": 0,
      "reply_count": 5,
      "view_count": 59,
      "posted_at": "2026-09-26T22:37:05+00:00",
      "author_username": "•••",
      "author_name": "•••",
      "author_url": "https://x.com/•••",
      "author_follower_count": 4258,
      "quote_count": 0,
      "bookmark_count": 0,
      "language": "en",
      "conversation_id": "2103610284464316469",
      "is_reply": true,
      "is_pinned": false,
      "reply_to_id": "2103610284464316469",
      "reply_to_user_id": "•••",
      "reply_to": "NASA",
      "mentions": [
        "Super_Powers_AI"
      ],
      "links": [
        "https://app.getsupers.com/sites/orbital-docking-trainer-48/?card=19b18230f989e036fe86"
      ],
      "author_id": "•••",
      "author_avatar_url": "https://pbs.twimg.com/•••",
      "author_is_verified": true,
      "author_following_count": 2051,
      "author_post_count": 24863,
      "author_media_count": 900,
      "author_created_at": "2011-09-19T23:33:41+00:00",
      "author_banner_url": "https://pbs.twimg.com/profile_banners/376478209/1753025143",
      "platform": "twitter"
    }
  ],
  "count": 20,
  "billing": {
    "charged": …,
    "charged_usd": …,
    "balance_after_usd": …,
    …
  },
  "quota": { … }
}
```

## FAQ

### 用评论做情绪抽样，样本够用吗？

不一定。单次最多读 50 条，不传 `limit` 时读 20 条；热门帖子的回复往往比这多，拿到的只是其中一部分，报告里要注明样本量。返回顺序没有说明，需要排序时自己按 `like_count` 或 `posted_at` 排。

### 回复者的信息放在哪些字段里？

`author_username` 是回复者的用户名，`author_follower_count` 是他的粉丝数，`author_is_verified` 是认证标识。把评论按 `author_follower_count` 排序，可以先看影响力大的账号怎么说；粉丝数为 null 的是没公开，排序时放到最后。

### 怎么把评论按讨论串归组？

用 `conversation_id`，它是所属对话串的 ID，也就是根推文的 ID，同一串的回复共用它。`reply_to_user_id` 是被回复用户的数字 ID，两者配合可以看出回复在回谁。

## 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
