# 怎样把三平台取数结果入库并保留各自的数据粒度？

[规范网址](https://social2api.com/guides/social2api-multi-platform-tables-grain/)

分别向 Social2api 查询三个 task，再按不同业务键写入源表。小红书用笔记 ID，抖音用关键词与日期，视频号先用 videoId 汇总作品，再从每行提取评论明细。

## Agent 提示词

~~~~text
请在 Social2api 使用三平台取数 API，执行以下任务。
目标：在共用结果信封下按源业务键保存三张粒度不同的表。
输入与对照示例：同一活动样例可以有 12 篇笔记、2 个关键词各 7 天的 14 个词日、3 条视频及 8 条评论明细。数据库保持不同数据粒度，汇报中按活动和日期范围并排读取。
公开查询可先用免密钥合成示例；实时取数需要权限和部署支持。
按以下步骤完成：为每次 POST /api/run 保存 task、params、时间范围、provider、warnings 和原始 JSON，以便回查。 将小红书一行一笔记、抖音一行一词日、视频号一行一条已取评论的结果分开解析。视频号作品表按 videoId 去重，评论原始结果保留批次。 只在跨平台报告层按研究主题和时间窗口做关联。缺失值和无记录日分别标记，三种不同来源的互动、指数或评论数分列展示。
交付能核对的结果和必要字段：rows[].id、rows[].keyword、rows[].date、rows[].videoId、rows[].commentText、warnings。注明来源或限制，并以本页为操作参考。
https://social2api.com/guides/social2api-multi-platform-tables-grain/
~~~~

[打开统一取数响应与示例](https://social2api.com/docs/api/run/)

## 本页用到的 Social2api 接口

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

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

1. 为每次 POST /api/run 保存 task、params、时间范围、provider、warnings 和原始 JSON，以便回查。
2. 将小红书一行一笔记、抖音一行一词日、视频号一行一条已取评论的结果分开解析。视频号作品表按 videoId 去重，评论原始结果保留批次。
3. 只在跨平台报告层按研究主题和时间窗口做关联。缺失值和无记录日分别标记，三种不同来源的互动、指数或评论数分列展示。

## 把合成响应拆成四张源表

可使用三平台字段验收指南中 POST /api/run 的三份 demo 响应。将 rednote-demo.json、douyin-demo.json 和 channels-demo.json 保存在同一目录，再用 Node.js 运行下面的示例。

笔记按 id 保留一条，趋势按 keyword 和 date 保留一条，作品按 videoId 保留一条。视频号评论只保留有正文的行，并记录原始行号以便回溯。在实时接入中，将响应、查询条件、provider 和 warnings 与自己的批次 ID 一起归档。

~~~~javascript
const { readFileSync } = require("node:fs");
const read = (task) => JSON.parse(readFileSync(task + "-demo.json", "utf8")).rows;
const byKey = (rows, getKey) => [...new Map(rows.map((row) => [getKey(row), row])).values()];
const notes = byKey(read("rednote"), (row) => row.id);
const trends = byKey(read("douyin"), (row) => JSON.stringify([row.keyword, row.date]));
const channelRows = read("channels");
const videos = byKey(channelRows.map(({ videoId, title, publishedAt, likes, commentCount, url }) =>
  ({ videoId, title, publishedAt, likes, commentCount, url })), (row) => row.videoId);
const comments = channelRows.map(({ videoId, commentText, commentAuthor, commentPublishedAt }, index) =>
  ({ sourceRow: index + 1, videoId, commentText, commentAuthor, commentPublishedAt }))
  .filter((row) => typeof row.commentText === "string" && row.commentText.trim());
console.table({ notes: notes.length, trends: trends.length, videos: videos.length, comments: comments.length });
~~~~

## 操作示例与核对

同一活动样例可以有 12 篇笔记、2 个关键词各 7 天的 14 个词日、3 条视频及 8 条评论明细。数据库保持不同数据粒度，汇报中按活动和日期范围并排读取。

## 需要核对的字段

rows\[\].id、rows\[\].keyword、rows\[\].date、rows\[\].videoId、rows\[\].commentText、warnings。

## 接口文档

- [抖音关键词逐日趋势](https://social2api.com/docs/api/douyin-keyword-trends/)
- [小红书公开笔记搜索](https://social2api.com/docs/api/rednote-notes-search/)
- [运行取数任务](https://social2api.com/docs/api/run/)
- [微信视频号作品与评论](https://social2api.com/docs/api/wechat-channels-videos/)

## 相关用户讨论

- [用户讨论 · YouTube、Instagram、Facebook · Best way to take data from Facebook, Instagram, YouTube and Twitch to a new database](https://www.reddit.com/r/dataengineering/comments/1f91ugd/best_way_to_take_data_from_facebook_instagram/)
- [用户讨论 · 跨平台 · How are you pulling social media data into n8n without maintaining different integration for every platform?](https://www.reddit.com/r/n8n/comments/1wn7oyz/how_are_you_pulling_social_media_data_into_n8n/)

## 相关指南和问答

- [n8n 接小红书、抖音和视频号，要分别装三个节点吗？](https://social2api.com/answers/social2api-n8n-http-node-for-chinese-platforms/)
- [没有真实 API Key，能先验证 Google Sheets 能否接收取数结果吗？](https://social2api.com/answers/social2api-load-demo-rows-into-google-sheets/)
- [重复提交同一个作品链接，Social2api 会自动去重或免掉重试费用吗？](https://social2api.com/answers/social2api-catalog-idempotency-vs-link-deduplicating/)
- [小红书、抖音、微信视频号的数据 API 怎么选？](https://social2api.com/answers/chinese-social-data-api-selection/)

[打开统一取数响应与示例](https://social2api.com/docs/api/run/)
