# 怎样把视频号结果拆成作品表和评论表？

[规范网址](https://social2api.com/guides/wechat-channels-separate-videos-and-comments-tables/)

在作品表每个 videoId 保留一行，评论表保留每条有正文的结果行，两张表均使用 videoId 做关联。

## Agent 提示词

~~~~text
请在 Social2api 使用微信视频号作品与评论，执行以下任务。
目标：将结果拆成一对多的两张关联表。
输入与对照示例：一个活动有 5 条作品、17 条返回评论。作品表保留 5 行，评论表保留 17 行，通过作品 ID 汇合。
公开查询可先用免密钥合成示例；实时取数需要权限和部署支持。
按以下步骤完成：运行视频号任务并导出一个批次。 为作品表保留 ID、标题、发布时间、点赞和评论总数，按 ID 去重。 为评论表保留 ID、正文、作者和时间，筛除无正文的占位行。
交付能核对的结果和必要字段：videoId、title、publishedAt、likes、commentCount、commentText、commentAuthor、commentPublishedAt。注明来源或限制，并以本页为操作参考。
https://social2api.com/guides/wechat-channels-separate-videos-and-comments-tables/
~~~~

[取一批作品和评论行](https://social2api.com/#workspace/channels)

[查看对应 API](https://social2api.com/docs/api/wechat-channels-videos/)

## 本页用到的 Social2api 接口

| 接口与参数文档 | 用途 |
| --- | --- |
| [微信视频号 视频评论列表](https://social2api.com/docs/api/catalog-wechat-channels-videos-comments-list/) · GET /v1/wechat\_channels/videos/comments/list | 微信视频号 视频评论列表。返回一页 data.items，以及可用的下一页游标。 |
| [微信视频号作品与评论](https://social2api.com/docs/api/wechat-channels-videos/) · POST /api/run · task=channels | 解析微信视频号账号，取回其公开视频以及每个视频的部分评论。 |

## 在 Social2api 使用微信视频号作品与评论

1. 运行视频号任务并导出一个批次。
2. 为作品表保留 ID、标题、发布时间、点赞和评论总数，按 ID 去重。
3. 为评论表保留 ID、正文、作者和时间，筛除无正文的占位行。

## 复制请求并试跑

用三条作品各两条合成评论练习拆成作品表及评论表，并按 videoId 检查一对多关系。

这条请求使用合成样例，免登录、免 API Key，上游请求数为 0。要查真实数据，将 mode 改为 live，换成实际输入，并在 Authorization 中提供有相应任务权限的 Bearer API Key。可用 maxRequests 限制实时上游请求数。

~~~~bash
curl --fail-with-body -sS 'https://social2api.com/api/run' \
  -H 'Content-Type: application/json' \
  --data-binary @- <<'JSON'
{
  "task": "channels",
  "mode": "demo",
  "params": {
    "account": "活动评论示例账号",
    "limit": 3,
    "commentsPerVideo": 2,
    "since": "2026-10-12",
    "until": "2026-10-18"
  }
}
JSON
~~~~

## 把托管响应拆成作品表和评论表

将原始响应保存为 channels.json，把代码存为 split\_channels.py 后运行 python3 split\_channels.py channels.json。输出 videos.csv 和 comments.csv，通过 videoId 关联。三条作品、每条两条评论的样例应生成 3 条作品行和 6 条评论行。

托管结果没有独立评论 ID。comments.csv 的 sourceRow 仅定位本份输入。跨批次保留取数批次和原始行，正文、昵称与时间指纹只用于找疑似重复。需要平台评论 ID 时，用视频号作品评论接口读取 data.items\[\].id 和关联作品 ID。

~~~~python
import csv, json, sys
from pathlib import Path
source = Path(sys.argv[1])
rows = json.loads(source.read_text(encoding='utf-8'))['rows']
video_columns = ['videoId', 'title', 'publishedAt', 'likes', 'commentCount', 'url']
comment_columns = ['videoId', 'commentText', 'commentAuthor', 'commentPublishedAt', 'sourceRow']
videos, comments = {}, []
for position, row in enumerate(rows, 1):
    video_id = row['videoId']
    if not isinstance(video_id, str) or not video_id:
        raise ValueError(f'Expected a string videoId on row {position}')
    videos.setdefault(video_id, row)
    if row.get('commentText'):
        comments.append({**row, 'sourceRow': position})
for filename, fields, records in [('videos.csv', video_columns, videos.values()),
                                  ('comments.csv', comment_columns, comments)]:
    with open(filename, 'w', encoding='utf-8-sig', newline='') as output:
        writer = csv.DictWriter(output, fieldnames=fields, extrasaction='ignore')
        writer.writeheader()
        writer.writerows(records)
print(f'{len(videos)} videos, {len(comments)} comments')
~~~~

## 操作示例与核对

一个活动有 5 条作品、17 条返回评论。作品表保留 5 行，评论表保留 17 行，通过作品 ID 汇合。

## 需要核对的字段

videoId、title、publishedAt、likes、commentCount、commentText、commentAuthor、commentPublishedAt。

## 接口文档

- [微信视频号作品与评论](https://social2api.com/docs/api/wechat-channels-videos/)

## 相关用户讨论

- [相邻平台类比 · TikTok · 进行 TikTok 定性研究时，如何把作品元数据、评论与回复整理成可用于 Excel 分析的数据？](https://www.reddit.com/r/CompSocial/comments/1fez5z8/)
- [相邻平台类比 · Instagram、TikTok、LinkedIn · 需要在 Instagram、TikTok 和 LinkedIn 逐帖查看数据。如何一次取得帖子和 Reels 的分析指标？](https://www.reddit.com/r/socialmedia/comments/1pddle9/)

## 相关指南和问答

- [如何批量获取微信视频号历史作品和评论并导出 CSV](https://social2api.com/guides/wechat-channels-export-videos-comments/)

[取一批作品和评论行](https://social2api.com/#workspace/channels)
