# 查 X（Twitter）公开帖子和回复，用搜索还是回复 API？

[规范网址](https://social2api.com/compare/x-public-post-search-and-replies-api/)

只有关键词时，用 Social2api 的 X 帖子搜索找候选。已有帖子 ID 时，用回复列表读取该帖可见回复。将搜索命中与回复分开计费，再把两个数据表按原帖 ID 关联。

DataXAPI 价目生效日期与版本 [2026-11-25 · v22](https://social2api.com/pricing-catalog.json)

## Agent 提示词

~~~~text
用 Social2api 完成「查 X（Twitter）公开帖子和回复，用搜索还是回复 API？」这项任务。
核对我提供的公开输入、所需输出字段和调用预算，尚缺输入时先询问。按页面列出的端点选择一次最小调用。只有我确认实时取数并配置所需密钥后才执行。
报告实际查询边界、取得的记录和缺失项，保留原始来源和采样时间。费用根据实际调用次数记录。
https://social2api.com/compare/x-public-post-search-and-replies-api/
~~~~

[搜索 X 公开帖子的接口文档](https://social2api.com/docs/api/catalog-x-posts-search/)

## 按你要交付的结果选方法

| 做法 | 适合的任务 | 要核对的条件 |
| --- | --- | --- |
| 网页回查 | 只需要复核少量已知内容 | 记录实际可见结果与观察时间。 |
| Social2api 帖子搜索 | 输入是词或短语 | 固定 query 和 sort 后开始取样。 |
| Social2api 回复列表 | 输入是某条公开帖的 ID | 固定原帖 ID 和游标，逐页保存返回。 |

## 对应的 Social2api 接口

| 接口 | 输入 | 交付结果 |
| --- | --- | --- |
| [搜索 X 公开帖子](https://social2api.com/docs/api/catalog-x-posts-search/) · GET /v1/x/posts/search | query，可选 sort=latest | 每页最多 20 条公开搜索结果。 |
| [读取 X 公开帖回复](https://social2api.com/docs/api/catalog-x-posts-replies-list/) · GET /v1/x/posts/replies/list | id 填原帖 ID | 每页最多 60 条，数据项是 Post。以输入原帖 ID 关联，保留可取得的 parent\_id。 |
| [读取 X 单帖详情](https://social2api.com/docs/api/catalog-x-posts-get/) · GET /v1/x/posts/get | id 或公开链接 | 用于核对可取的原帖字段。 |

## 从输入到可以核对的交付

交付搜索结果表与回复表，留存原帖 ID、回查链接、采样时刻和可用字段。

1. **先保存候选 ID**。 给每组检索保留查询词、具体排序和取样时刻。搜索到的 id 保持字符串，避免数字精度丢失。
2. **展开已知帖子**。 选定搜索结果的 id 作为原帖输入。回复返回 Post，对每条回复用其自身 id 去重，并单独保留查询的原帖 id、可取得的 parent\_id 和返回链接。
3. **核对更新延迟**。 比较返回的发布时间和本地发现时间，观察当前查询批次的延迟。无时间的项目单列。

## 最小调用示例

将有 catalog 权限的 Social2api API Key 和自带的 DataXAPI Key 分别放在 SOCIAL2API\_API\_KEY 和 DATAXAPI\_API\_KEY。示例的 X-Max-Price 固定 DataXAPI 通道，并限制每次费用。

搜索一页，选首个有 ID 的原帖。保存最多两页回复和一份原帖详情，写出可关联的 x-replies.jsonl。查询原帖 ID 保存为 source\_post\_id。

~~~~bash
set -eu
: "${SOCIAL2API_API_KEY:?Set a Social2api catalog key}" "${DATAXAPI_API_KEY:?Set a DataXAPI key}"

curl -fsS --get 'https://social2api.com/v1/x/posts/search' \
  -H "Authorization: Bearer $SOCIAL2API_API_KEY" \
  -H "X-DataXAPI-Key: $DATAXAPI_API_KEY" \
  -H 'X-Max-Price: 0.002' \
  --data-urlencode 'query=weather forecast' \
  --data-urlencode 'sort=latest' > x-search.json
jq -e '.code == "ok"' x-search.json >/dev/null
POST_ID=$(jq -r 'first(.data.items[]? | .id | select(type == "string" and length > 0)) // empty' x-search.json)
[ -n "$POST_ID" ] || { printf "%s\n" "No matching X post returned" >&2; exit 0; }
curl -fsS --get 'https://social2api.com/v1/x/posts/replies/list' \
  -H "Authorization: Bearer $SOCIAL2API_API_KEY" \
  -H "X-DataXAPI-Key: $DATAXAPI_API_KEY" \
  -H 'X-Max-Price: 0.002' \
  --data-urlencode "id=$POST_ID" > x-replies-first.json
jq -e '.code == "ok"' x-replies-first.json >/dev/null
CURSOR=$(jq -r 'if .page.has_more then .page.next_cursor // empty else empty end' x-replies-first.json)
if [ -n "$CURSOR" ]; then
curl -fsS --get 'https://social2api.com/v1/x/posts/replies/list' \
  -H "Authorization: Bearer $SOCIAL2API_API_KEY" \
  -H "X-DataXAPI-Key: $DATAXAPI_API_KEY" \
  -H 'X-Max-Price: 0.002' \
  --data-urlencode "id=$POST_ID" \
  --data-urlencode "cursor=$CURSOR" > x-replies-second.json
jq -e '.code == "ok"' x-replies-second.json >/dev/null
  reply_files="x-replies-first.json x-replies-second.json"
else
  reply_files=x-replies-first.json
fi
curl -fsS --get 'https://social2api.com/v1/x/posts/get' \
  -H "Authorization: Bearer $SOCIAL2API_API_KEY" \
  -H "X-DataXAPI-Key: $DATAXAPI_API_KEY" \
  -H 'X-Max-Price: 0.0003' \
  --data-urlencode "id=$POST_ID" > x-original-post.json
jq -e '.code == "ok"' x-original-post.json >/dev/null
jq -cs --arg source_post_id "$POST_ID" '
  [.[] | .data.items[]?] | unique_by(.id)[] |
  {source_post_id: $source_post_id, reply_id: .id, parent_id, text, published_at, url}
' $reply_files > x-replies.jsonl
cat x-replies.jsonl
~~~~

## 输出样例（合成数据）

| source\_post\_id | reply\_id | parent\_id | 对象 |
| --- | --- | --- | --- |
| demo-origin | demo-reply | demo-origin | Post 回复 |

## 这组样本要多少次调用？

按 DataXAPI 通道参考价，每个请求（包括每次续页）单独计算。示例安排 4 次请求。按每次上限估算，1 × 0.002 + 2 × 0.002 + 1 × 0.0003 = 0.0063 USD。

此估算按下表的调用次数计算，未包含额外翻页和重试。供应商费用在你的 DataXAPI 账户结算。

| 试跑任务 | 请求数 | DataXAPI 通道每次上限 |
| --- | --- | --- |
| 搜索 X 公开帖子 | 1 | 0.002 USD |
| 读取 X 公开帖回复 | 2 | 0.002 USD |
| 读取 X 单帖详情 | 1 | 0.0003 USD |

## 用户在比较什么

- **获取 X 公开帖与回复并重复更新的需求** 问题涉及搜索、串内回复、原帖链接和更新频率。 [获取 X 公开帖与回复并重复更新的需求](https://www.reddit.com/r/Saudi_Devs/comments/1wq3c2t/)

## 常见问题

### 回复接口可以直接拿关键词作查询吗？

回复列表要求原帖 id。有关键词时先搜索帖子，再选择要展开的原帖。

## 接口文档

- [搜索 X 公开帖子](https://social2api.com/docs/api/catalog-x-posts-search/)
- [读取 X 公开帖回复](https://social2api.com/docs/api/catalog-x-posts-replies-list/)
- [读取 X 单帖详情](https://social2api.com/docs/api/catalog-x-posts-get/)
- [核对 DataXAPI 通道价目表](https://social2api.com/pricing-catalog.json)

## 参考来源

- [DataXAPI X 回复与详情教程](https://dataxapi.com/zh/guides/x-post-replies/)

## 相关用户讨论

- [获取 X 公开帖与回复并重复更新的需求](https://www.reddit.com/r/Saudi_Devs/comments/1wq3c2t/)

## 给 AI 代理

- [给 AI 的站点说明](https://social2api.com/zh/llms.txt)。 面向代理的功能概览与文档发现索引。
- [接入 AI 的步骤](https://social2api.com/zh/agents/)。 从免费试跑到 API Key 与 MCP 接入。
- [接入步骤（Markdown）](https://social2api.com/agents.md)。 接入指南的纯文本 Markdown 版本。
- [OpenAPI](https://social2api.com/openapi.json)。 查看 HTTP 请求参数、认证方式和响应结构。
- [价格表](https://social2api.com/prices.json)。 查看托管积分规则、扩展 API 报价和充值状态。
- [MCP 地址](https://social2api.com/docs/api/mcp/)。 Streamable HTTP 接入、授权方式和工具说明。

MCP Streamable HTTP 地址 `https://social2api.com/mcp`。

## 相关指南和问答

- [怎样按关键词筛选 X 公开列表里的帖子？](https://social2api.com/guides/filter-x-public-list-posts-by-keyword/)
- [怎样把 X 账号的公开帖子导出到 CSV？](https://social2api.com/guides/export-x-user-posts-to-csv/)
- [社媒数据 API 选型与对比](https://social2api.com/compare/)

[搜索 X 公开帖子的接口文档](https://social2api.com/docs/api/catalog-x-posts-search/)
