X (Twitter) 评论 API
接口健康状态
- 24h 健康值
- 正常
- 健康 / 正常
- 可用
- 少量可用
- 基本不可用
24 小时趋势
30 天趋势
评论:返回列表,默认 20 条、单次最多 50 条;主要字段 id、url、text、like_count、retweet_count、reply_count。
请求发到 POST https://api.everyinfra.com/api/v1/social,platform 填 twitter,action 填 comments。 单价 $0.56 / 千次(每次 $0.000556),失败和空结果都不收费。 同步返回;慢任务可在请求体加 "mode": "async",先拿 job_id 再轮询。
推文评论按 id 读取一条帖子的回复。每条都是一条完整的帖子记录:正文、点赞、转发、浏览数、回复者的用户名和粉丝数。它回答「读者怎么回应这条帖子」,适合做口碑与情绪抽样、收集产品反馈,或者挑出被大量点赞的回复;media 里还有回复附带的图片或视频。
传的是被评论的那条帖子的 ID,不是某条评论的 ID。id 填 x.com/用户名/status/ 后面的数字,不要放完整链接。同一个 id 在单条内容那一页读帖子本身,在这一页读它的回复。
AI 提示词
#请帮我用 EveryInfra 的「X (Twitter) 评论」接口(twitter/comments)写一个数据采集脚本。
接口约定:
- 请求:POST https://api.everyinfra.com/api/v1/social,请求头 Authorization: Bearer <API Key>;Key 从环境变量 EVERYINFRA_API_KEY 读取,不要写进代码。
- 请求体里 platform 填 twitter,action 填 comments,参数放在 params 里。
- 必填参数:
- id:post / comments 的数字帖子 ID,即 x.com/用户名/status/ 后的数字,建议用字符串保存以避免 JavaScript 大整数精度损失;不要把完整 URL 放入 id。
- 可选参数:
- tweet_id:id 的兼容输入,优先级低于 id,不取消公开必填 id。
- limit:这次调用最多返回的条数,整数,1–50;不传按默认值,实际返回可能少于这个数。超过上限会在扣费前返回 422。(默认 20)
- 返回一组记录,每条记录的主要字段:id、url、text、like_count、retweet_count(转发数)、reply_count、view_count、posted_at、author_username、author_name、author_url、author_follower_count;一共 37 个字段,完整列表见 https://api.everyinfra.com/api/v1/social/catalog?platform=twitter。
- 示例请求体:
{
"platform": "twitter",
"action": "comments",
"params": {
"id": "2103610284464316469"
}
}
- 计费:$0.56 / 千次;失败和空结果不扣费。
- 一次要采几十上百个时,在请求体加 "mode": "async":先拿到 job_id,再轮询 GET https://api.everyinfra.com/api/v1/jobs/{job_id} 取结果。
- 返回 422 时,按错误信息里的候选参数和允许值修正;返回 429 或 503 时,按 Retry-After 等待后重试。
写代码前,先问清楚我要采哪些对象、一共多少个、需要哪些字段、结果存成什么格式,再把方案和大概花费讲给我确认。请求参数
#| 参数名 | 位置 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|---|
Authorization | header | string | 是 | - | Bearer 加你的 API Key。在控制台创建;不要放进网址或代码仓库。 |
platform | body | string | 是 | twitter | 平台标识,固定值。 |
action | body | string | 是 | comments | 能力标识,固定值。 |
id | body.params | string | 是 | - | post / comments 的数字帖子 ID,即 x.com/用户名/status/ 后的数字,建议用字符串保存以避免 JavaScript 大整数精度损失;不要把完整 URL 放入 id。 |
tweet_id | body.params | string | 否 | - | id 的兼容输入,优先级低于 id,不取消公开必填 id。 |
limit | body.params | integer (1–50) | 否 | 20 | 这次调用最多返回的条数,整数,1–50;不传按默认值,实际返回可能少于这个数。超过上限会在扣费前返回 422。 |
代码示例
#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"
}
}'OpenAPI 定义 (JSON)示例从环境变量 EVERYINFRA_API_KEY 读取 Key,复制出去的代码不含你的 Key。
响应示例
#{ "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": { … }}
返回字段
#业务数据在 results 里;下表是每条记录可能包含的字段,平台没有提供的值不会被编造。
| 字段 | 含义 |
|---|---|
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 | 保留平台原语义 |
bookmark_count | 书签(收藏)数。 |
language | 内容语言代码(如 zh、en),由平台判定,可能不准。 |
conversation_id | 所属对话串 ID(根推文 ID),同一串的回复据此归在一起。 |
is_reply | 保留平台原语义 |
is_quote | 是否引用推文。 |
is_repost | 保留平台原语义 |
is_pinned | 保留平台原语义 |
reply_to_id | 保留平台原语义 |
reply_to_user_id | 所回复用户的数字 ID。 |
reply_to | 保留平台原语义 |
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 | 保留平台原语义 |
author_is_verified | 保留平台原语义 |
author_following_count | 保留平台原语义 |
author_post_count | 作者推文总数。 |
author_media_count | 作者发过的媒体数。 |
author_created_at | 保留平台原语义 |
author_banner_url | 作者主页横幅图链接。 |
platform | 数据来源平台标识,与请求里的 platform 一致(如 xiaohongshu、tiktok)。 |
常见问题
#用评论做情绪抽样,样本够用吗?
#不一定。单次最多读 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,两者配合可以看出回复在回谁。
错误与计费
#- 401
- 缺少 Key 或 Key 无效。
- 402
- 余额不足,先充值。
- 422
- 参数名或取值不对,按错误信息给的候选改;不扣费。
- 429
- 超过每分钟请求上限,按 Retry-After 等待后再试。
- 503
- 暂时无法完成,预扣的费用退回;结果未知时先核对,不要直接重发。
- 200 空结果
- 没有数据,不扣费。