# 如何在接入真实数据源前测试三个取数接口的字段？

[规范网址](https://social2api.com/guides/social2api-demo-contract-acceptance/)

先用 POST /api/run 的 demo 模式取一份每个平台的合成响应，验证 columns、rows、warnings 和 requestCount，再配置真实数据源。

## Agent 提示词

~~~~text
请在 Social2api 使用三平台取数 API，执行以下任务。
目标：用免密钥演示响应为解析器建立可重复的契约样例。
输入与对照示例：选择一个笔记样例、两个关键词各 7 天和两个视频各 3 条评论，解析器分别检查笔记行、14 个词日和 6 个评论行。合成样例用于字段验收。
公开查询可先用免密钥合成示例；实时取数需要权限和部署支持。
按以下步骤完成：选择固定的日期和非空示例输入，分别调用 rednote、douyin 和 channels，记录响应副本。demo 可省略密钥。 按每个 task 校验列名和行粒度。脚本接受 URL 或指数等可为空字段，并保留未知字段，便于兼容上游变化。 本地验收检查 mode 是 demo、requestCount 是 0，合成值没有写入业务报表。切换到实时环境时重新验证权限、字段缺失和上游 warnings。
交付能核对的结果和必要字段：mode、columns、rows、warnings、requestCount。注明来源或限制，并以本页为操作参考。
https://social2api.com/guides/social2api-demo-contract-acceptance/
~~~~

[查看可直接执行的取数示例](https://social2api.com/docs/api/run/)

## 本页用到的 Social2api 接口

| 接口与参数文档 | 用途 |
| --- | --- |
| [运行取数任务](https://social2api.com/docs/api/run/) · POST /api/run | 用同一接口运行三种平台任务，返回标准化列、结果行、提示和实际上游请求数。 |
| [检查数据源配置](https://social2api.com/docs/api/status/) · GET /api/status | 查看服务端配置的供应商、各平台是否具备实时数据源，以及参数上限。 |
| [小红书公开笔记搜索](https://social2api.com/docs/api/rednote-notes-search/) · POST /api/run · task=rednote | 按关键词搜索公开笔记，并可用发布日期和结果条数收窄范围。 |
| [抖音关键词逐日趋势](https://social2api.com/docs/api/douyin-keyword-trends/) · POST /api/run · task=douyin | 查询最多 20 个关键词的日搜索指数和可用的综合指数。 |
| [微信视频号作品与评论](https://social2api.com/docs/api/wechat-channels-videos/) · POST /api/run · task=channels | 解析微信视频号账号，取回其公开视频以及每个视频的部分评论。 |

## 在 Social2api 使用三平台取数 API

1. 选择固定的日期和非空示例输入，分别调用 rednote、douyin 和 channels，记录响应副本。demo 可省略密钥。
2. 按每个 task 校验列名和行粒度。脚本接受 URL 或指数等可为空字段，并保留未知字段，便于兼容上游变化。
3. 本地验收检查 mode 是 demo、requestCount 是 0，合成值没有写入业务报表。切换到实时环境时重新验证权限、字段缺失和上游 warnings。

## 运行并验收三份免费样例

以下命令会把三个固定日期的 demo 响应写入当前目录，再用 Node.js 检查 task、mode、columns、rows、warnings 和 requestCount。运行需要 curl 和 Node.js，无需登录或密钥。

预期返回一条小红书笔记、14 条抖音词日数据、两条视频号作品的六条评论行。验收以合成样例为输入，切换到实时后仍需检查授权、缺失字段和 warnings。

~~~~bash
(
  set -eu
  run_demo() {
    curl -fsS https://social2api.com/api/run \
      -H "Content-Type: application/json" --data "$2" -o "$1-demo.json"
  }
  run_demo rednote '{"task":"rednote","mode":"demo","params":{"query":"骑行","since":"2026-10-01","until":"2026-10-07","limit":1}}'
  run_demo douyin '{"task":"douyin","mode":"demo","params":{"keywords":["骑行","城市骑行"],"since":"2026-10-01","until":"2026-10-07"}}'
  run_demo channels '{"task":"channels","mode":"demo","params":{"account":"城市骑行","since":"2026-10-01","until":"2026-10-07","limit":2,"commentsPerVideo":3}}'
  node --input-type=module <<'JS'
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
const expected = {
  rednote: { count: 1, fields: ["id", "title", "publishedAt"] },
  douyin: { count: 14, fields: ["keyword", "date", "searchIndex", "combinedIndex"] },
  channels: { count: 6, fields: ["videoId", "commentText"] },
};
for (const [task, { count, fields }] of Object.entries(expected)) {
  const result = JSON.parse(readFileSync(task + "-demo.json", "utf8"));
  assert.equal(result.task, task);
  assert.equal(result.mode, "demo");
  assert.equal(result.requestCount, 0);
  assert.equal(result.rows.length, count);
  assert.ok(Array.isArray(result.warnings));
  const keys = new Set(result.columns.map(({ key }) => key));
  assert.ok(fields.every((field) => keys.has(field)));
  assert.ok(result.rows.every((row) => fields.every((field) => Object.hasOwn(row, field))));
  console.log(task, count);
}
JS
)
~~~~

## 操作示例与核对

选择一个笔记样例、两个关键词各 7 天和两个视频各 3 条评论，解析器分别检查笔记行、14 个词日和 6 个评论行。合成样例用于字段验收。

## 需要核对的字段

mode、columns、rows、warnings、requestCount。

## 接口文档

- [运行取数任务](https://social2api.com/docs/api/run/)
- [检查数据源配置](https://social2api.com/docs/api/status/)

## 相关用户讨论

- [用户讨论 · YouTube · Which unified API tool works best in n8n for domain traffic, social posts, and work email lookups?](https://www.reddit.com/r/n8n/comments/1y2is25/which_unified_api_tool_works_best_in_n8n_for/)
- [用户讨论 · 小红书、抖音 · 公开数据工具遇到上游变化，怎么控制维护成本？](https://x.com/ReignSwords/status/2116310294167482672)

## 相关指南和问答

- [没有真实 API Key，能先验证 Google Sheets 能否接收取数结果吗？](https://social2api.com/answers/social2api-load-demo-rows-into-google-sheets/)
- [为什么工作台取数代码读取 rows，扩展接口却从 data.items 取数据？](https://social2api.com/answers/social2api-api-response-rows-vs-catalog-items/)
- [小红书、抖音、微信视频号的数据 API 怎么选？](https://social2api.com/answers/chinese-social-data-api-selection/)

[查看可直接执行的取数示例](https://social2api.com/docs/api/run/)
