# 怎么让 AI 搭一个自媒体数据工作台？抖音、小红书、公众号一起更新（2026）

把要看的账号和下面这份脚本交给 AI 就行：脚本取每个账号最新的作品，按编号去重存进本地数据库，再生成一个网页和一张表格。 用 3 个接口：抖音用户视频 → 小红书用户笔记 → 微信公众号文章列表。下面的示例一共 3 次调用，合计 $0.0420；失败的调用不收费。

更新于 2026-11-29

最后得到三个文件：`workbench.db`（存下来的全部作品）、`workbench.html`（浏览器直接打开的工作台，这次刚发现的作品标 NEW）和 `posts.csv`（Excel 能打开）。再跑一次就是刷新。

## 一步一步做

### 第 1 步：抖音用户视频

取一个抖音账号最新的一页作品。`id` 填账号编号（MS4w 开头的那一串）；手里只有主页链接，就把链接放进 `url`。每条作品的编号在 `id`，互动数在 `metrics`。（[抖音用户视频](https://dataxapi.com/zh/apis/douyin/users/videos/list/)，$0.0020 / 一次）

cURL

```bash
curl -G "https://api.dataxapi.com/v1/douyin/users/videos/list" \
  --data-urlencode "id=MS4wLjABAAAAZ0aPDJzFhBrs0q3wVsp2a9WWrBuAUMsVyygoaO0bCw8" \
  -H "Authorization: Bearer $DATAXAPI_API_KEY"
```

Python

```python
# pip install dataxapi
from dataxapi import DataXAPI

dx = DataXAPI()  # reads DATAXAPI_API_KEY
result = dx.douyin.users.videos.list(id="MS4wLjABAAAAZ0aPDJzFhBrs0q3wVsp2a9WWrBuAUMsVyygoaO0bCw8")
print(result["data"]["items"])
```

TypeScript

```typescript
// npm i @dataxapi/sdk
import { DataXAPI } from "@dataxapi/sdk";

const dx = new DataXAPI(); // reads DATAXAPI_API_KEY
const result = await dx.douyin.users.videos.list({ id: "MS4wLjABAAAAZ0aPDJzFhBrs0q3wVsp2a9WWrBuAUMsVyygoaO0bCw8" });
console.log(result.data.items);
```

命令行

```bash
dataxapi call douyin.users.videos.list id=MS4wLjABAAAAZ0aPDJzFhBrs0q3wVsp2a9WWrBuAUMsVyygoaO0bCw8
```

录制的返回：取自 2026-10-29 11:25 UTC 录下的真实返回。名字、正文和编号是示例，链接也是，都不是录到的原文（页面不展示任何人的个人信息）；数字是原样。长列表做了截断。请求号、游标和余额是示意。

```jsonc
{
  "code": "ok",
  "request_id": "c2504d6c-2152-4538-a486-725d6f7948f6",
  "data": {
    "items": [
      {
        "id": "7302312618550095845",
        "url": "https://www.douyin.com/video/7302312618550095845",
        "type": "video",
        "title": "关于周末露营，我踩过的五个坑",
        "text": "把周末露营从头到尾讲清楚，看完少走弯路",
        "lang": "zh",
        "published_at": "2026-10-28T13:00:00.000Z",
        "author": {
          "id": "MS4wLjABAAAAISQZJVj44x7UmGOrbYT9MYgZqmQZXyVYh0J_KeP0bY6",
          "username": "orange_soda22",
          "name": "橘子汽水不加冰",
          "avatar_url": "https://p3-pc.douyinpic.com/aweme/100x100/aweme-avatar/tos-cn-avt-0015_edc4afa9b9ce65d8c81c.jpeg"
        },
        "metrics": {
          "likes": 9137,
          "comments": 822,
          "shares": 2501,
          "favorites": 1252
        },
        "images": null,
        "hashtags": [
          "户外生活",
          "好物分享",
          // … 另有 3 条
        ],
        "is_pinned": false
      },
      // … 另有 19 条
    ]
  },
  "page": {
    "next_cursor": "c1.WtpNZgnDx-u92cDS4sHsDBAjGm-hJOPNKEKmB3hJ",
    "cursor_expires_at": "2026-10-29T12:25:19.000Z",
    "has_more": true,
    "returned": 20
  },
  "warnings": [],
  "meta": {
    "capability": "douyin.users.videos.list",
    "result_status": "complete",
    "fetched_at": "2026-10-29T11:25:19.000Z",
    "cached": false,
    "replayed": false,
    "unavailable": {
      "metrics.views": "capability",
      "metrics.reposts": "platform",
      "author.verified": "capability",
      "mentions": "capability",
      "post_id": "platform",
      "parent_id": "platform",
      "root_id": "platform",
      "author.followers": "capability"
    },
    "billing": {
      "amount": "0.002",
      "currency": "USD",
      "balance_after": "9.998"
    }
  }
}
```

### 第 2 步：小红书用户笔记

取一个小红书账号最新的一页笔记，`id` 是 24 位用户编号，也可以把主页链接放进 `url`。脚本要用的字段和上一步同名（这里没有 `url`），所以同一段代码就能存。（[小红书用户笔记](https://dataxapi.com/zh/apis/xiaohongshu/users/notes/list/)，$0.0200 / 一次）

cURL

```bash
curl -G "https://api.dataxapi.com/v1/xiaohongshu/users/notes/list" \
  --data-urlencode "id=63bed214000000002702b862" \
  -H "Authorization: Bearer $DATAXAPI_API_KEY"
```

Python

```python
# pip install dataxapi
from dataxapi import DataXAPI

dx = DataXAPI()  # reads DATAXAPI_API_KEY
result = dx.xiaohongshu.users.notes.list(id="63bed214000000002702b862")
print(result["data"]["items"])
```

TypeScript

```typescript
// npm i @dataxapi/sdk
import { DataXAPI } from "@dataxapi/sdk";

const dx = new DataXAPI(); // reads DATAXAPI_API_KEY
const result = await dx.xiaohongshu.users.notes.list({ id: "63bed214000000002702b862" });
console.log(result.data.items);
```

命令行

```bash
dataxapi call xiaohongshu.users.notes.list id=63bed214000000002702b862
```

录制的返回：取自 2026-10-12 19:13 UTC 录下的真实返回。名字、正文和编号是示例，链接也是，都不是录到的原文（页面不展示任何人的个人信息）；数字是原样。长列表做了截断。请求号、游标和余额是示意。

```jsonc
{
  "code": "ok",
  "request_id": "207ddb09-2a0d-4ff5-8cd3-9ddce35b46a5",
  "data": {
    "items": [
      {
        "id": "676ed1bc00000000d870f54e",
        "type": "video",
        "title": "实测一个月周末露营，结论有点意外",
        "text": "周末的周末露营日常，随手记录一下",
        "published_at": "2026-10-12T01:00:27.000Z",
        "author": {
          "id": "6998fff50000000046ca2f74",
          "name": "南边的风",
          "avatar_url": "https://sns-avatar-qc.xhscdn.com/avatar/6412ba1a00000000ff300cc2.jpg"
        },
        "metrics": {
          "likes": 8,
          "comments": 0,
          "shares": 0,
          "favorites": 2
        },
        "images": [
          "https://sns-webpic-qc.xhscdn.com/20261019/e38ec1fd03381eaef493!nd_dft_wlteh_webp_3"
        ],
        "mentions": [],
        "is_pinned": false
      },
      // … 另有 19 条
    ]
  },
  "page": {
    "next_cursor": "c1.LwegQikqZdn9JGQkwTrpD-r4Bc3_yNoolTMdaIit",
    "cursor_expires_at": "2026-10-12T20:13:48.000Z",
    "has_more": true,
    "returned": 20
  },
  "warnings": [],
  "meta": {
    "capability": "xiaohongshu.users.notes.list",
    "result_status": "complete",
    "fetched_at": "2026-10-12T19:13:48.000Z",
    "cached": false,
    "replayed": false,
    "unavailable": {
      "url": "capability",
      "lang": "capability",
      "author.username": "capability",
      "author.verified": "capability",
      "author.followers": "capability",
      "metrics.views": "platform",
      "metrics.reposts": "platform",
      "hashtags": "capability",
      "mentions.username": "platform",
      "post_id": "platform",
      "parent_id": "platform",
      "root_id": "platform"
    },
    "billing": {
      "amount": "0.02",
      "currency": "USD",
      "balance_after": "9.98"
    }
  }
}
```

### 第 3 步：微信公众号文章列表

取一个公众号最新的一页文章，`id` 填公众号的原始编号（大多以 gh_ 开头）。只知道名字时，先用 `wechat.accounts.search` 查编号，查一次就够，记进账号清单。（[微信公众号文章列表](https://dataxapi.com/zh/apis/wechat_mp/accounts/articles/list/)，$0.0200 / 一次）

cURL

```bash
curl -G "https://api.dataxapi.com/v1/wechat_mp/accounts/articles/list" \
  --data-urlencode "id=gh_13c97ab93ce8" \
  -H "Authorization: Bearer $DATAXAPI_API_KEY"
```

Python

```python
# pip install dataxapi
from dataxapi import DataXAPI

dx = DataXAPI()  # reads DATAXAPI_API_KEY
result = dx.wechat_mp.accounts.articles.list(id="gh_13c97ab93ce8")
print(result["data"]["items"])
```

TypeScript

```typescript
// npm i @dataxapi/sdk
import { DataXAPI } from "@dataxapi/sdk";

const dx = new DataXAPI(); // reads DATAXAPI_API_KEY
const result = await dx.wechat_mp.accounts.articles.list({ id: "gh_13c97ab93ce8" });
console.log(result.data.items);
```

命令行

```bash
dataxapi call wechat_mp.accounts.articles.list id=gh_13c97ab93ce8
```

录制的返回：取自 2026-10-12 19:02 UTC 录下的真实返回。名字、正文和编号是示例，链接也是，都不是录到的原文（页面不展示任何人的个人信息）；数字是原样。长列表做了截断。请求号、游标和余额是示意。

```jsonc
{
  "code": "ok",
  "request_id": "882b7d3d-9a50-48d1-ba28-513bec440e40",
  "data": {
    "items": [
      {
        "id": "2651350693_1",
        "url": "https://mp.weixin.qq.com/s/yEmemDFnwYkjLklz1HGeGz",
        "type": "article",
        "title": "实测一个月周末露营，结论有点意外",
        "text": null,
        "published_at": "2026-10-12T13:35:48.000Z",
        "author": { "id": "gh_baa95f56a86c" }
      },
      // … 另有 9 条
    ]
  },
  "page": {
    "next_cursor": "c1.c3D9oI16A0J5E0SMD5JU_mAesJzXbexIUP2nOHbv",
    "cursor_expires_at": "2026-10-12T20:02:58.000Z",
    "has_more": true,
    "returned": 10
  },
  "warnings": [],
  "meta": {
    "capability": "wechat_mp.accounts.articles.list",
    "result_status": "complete",
    "fetched_at": "2026-10-12T19:02:58.000Z",
    "cached": false,
    "replayed": false,
    "unavailable": {
      "lang": "capability",
      "author.username": "capability",
      "author.name": "capability",
      "author.avatar_url": "capability",
      "author.verified": "capability",
      "author.followers": "capability",
      "metrics": "capability",
      "images": "capability",
      "hashtags": "platform",
      "mentions": "platform",
      "is_pinned": "capability",
      "post_id": "platform",
      "parent_id": "platform",
      "root_id": "platform"
    },
    "billing": {
      "amount": "0.02",
      "currency": "USD",
      "balance_after": "9.98"
    }
  }
}
```

## 示例花多少钱

三个平台各一个账号，各取最新一页，也就是刷新一次。每多一个账号，就加一次那个平台的单价

| 接口 | 调用次数 | 单价 | 小计 |
| --- | --- | --- | --- |
| [抖音用户视频](https://dataxapi.com/zh/apis/douyin/users/videos/list/) | 1 | $0.0020 | $0.0020 |
| [小红书用户笔记](https://dataxapi.com/zh/apis/xiaohongshu/users/notes/list/) | 1 | $0.0200 | $0.0200 |
| [微信公众号文章列表](https://dataxapi.com/zh/apis/wechat_mp/accounts/articles/list/) | 1 | $0.0200 | $0.0200 |
| 合计 | 3 |  | $0.0420 |

价格是生成本页时的现行价格。失败的调用不收费。

## 在 AI 里做（MCP）

把 DataXAPI 接进你的 AI 客户端，只要接一次。之后直接说要什么，代理自己找到这些接口、看好价格，用你的余额调用。

这样说：用 DataXAPI 帮我搭一个数据工作台：读取我给你的抖音、小红书、公众号账号最新的作品，按编号去重存进 SQLite，生成一个按发布时间排序的网页和一张 CSV，新作品标出来。Key 从环境变量 DATAXAPI_API_KEY 读，先告诉我刷新一次要花多少钱。

代理发给 call 工具的参数：

```json
{
  "capability": "douyin.users.videos.list",
  "id": "MS4wLjABAAAAZ0aPDJzFhBrs0q3wVsp2a9WWrBuAUMsVyygoaO0bCw8",
  "idempotency_key": "<a new UUID>"
}
```

[了解 MCP 服务](https://dataxapi.com/zh/mcp/)

## 为什么用 DataXAPI

- 稳定：近 30 天接口可用 100%，状态页公开，可以自己核对。
- 快：近 7 天付费调用的中位耗时 2.2 秒（2026-11-06 统计）。
- 省 token：抖音的 36 个接口各取一份录制的真实返回，平台原始 JSON 合计 237.7 万 token，AI 通过 DataXAPI 的 MCP 读到的只有 7.2 万 token，少 97%；直接调接口拿到的 JSON 也少 96%（2026-11-06 统计）。所有平台同一种格式：作者在 `author`，互动数在 `metrics`，翻页用 `page.next_cursor`，换平台不用重写解析。
- 先看再用：每个接口的页面上都有一份录制的真实返回，字段一目了然。
- 花钱可控：失败不收费；每把 Key 能设金额上限，`X-Max-Price` 限定一次最多花多少，同一个 `Idempotency-Key` 24 小时内不重复扣费。
- 接 AI 方便：远程 MCP 服务已在 MCP 官方登记处登记（`com.dataxapi/mcp`），Claude、Cursor、ChatGPT 都能直接用。
- 免费试用，最多 333 次，不用绑卡。

## 要知道的

- 要用能在你电脑上运行代码的 AI，比如 Claude Code、Codex。想自己跑，就把脚本存成 `workbench.py`，装好 SDK、设好 Key，运行 `python3 workbench.py`，再打开 `workbench.html`。
- 换成你的账号：只改脚本开头的 `ACCOUNTS`，一行一个。账号名字随便起；第一列的平台名定好就别再改，去重要用。要加视频号，就加一行 `wechat_channels.users.videos.list`，`id` 填以 `@finder` 结尾的账号编号。
- 同一条作品只存一次，按平台加编号认；再次取到时只更新点赞和评论数。某个账号取不到时会跳过它并打印原因，其他账号照常保存。2026-11-29 连着跑了两遍：第一遍 89 条都标 NEW，第二遍 0 条。
- 公众号的文章列表不带互动数，所以公众号文章的 `likes` 和 `comments` 两列是空的。要看阅读、点赞和评论数，再用 `wechat_mp.articles.metrics` 逐篇取，按次另计费，只取新文章就不会多花。
- 小红书的笔记列表不带链接，所以 `url` 一列是空的。要打开某一篇，把最后一列的 `id` 传给 `xiaohongshu.notes.get`，返回里有链接，按次另计费。
- 每天自动更新：让电脑或服务器定时跑这份脚本，Mac 和 Linux 用 cron，Windows 用“任务计划程序”。定时任务读不到你在终端里设的 Key，要另外给它：cron 可以写成 `0 8 * * * DATAXAPI_API_KEY=dx_... /python3的完整路径 /脚本的完整路径`，也就是每天 8 点跑（Python 的完整路径用 `which python3` 查）；Windows 把 Key 加到用户环境变量里。刷新一次每个账号各取一页，一天刷新几次就按几次算。
- Key 只放在跑脚本的那台机器的环境变量里。生成的网页里没有 Key，可以发给同事看；要是让 AI 改成在线网站，Key 也要留在服务端，不要写进网页代码。

## 完整脚本

上面这件事写成一个能直接跑的脚本：Python，用 SDK，Key 从 DATAXAPI_API_KEY 读。它写出 workbench.db、workbench.html 和 posts.csv 三个文件，最后打印调了几次、取到几条、扣了多少。

```python
# pip install dataxapi
# export DATAXAPI_API_KEY=dx_...   (your key)
import csv
from decimal import Decimal
from dataxapi import DataXAPI

dx = DataXAPI()
calls, fetched, charged = 0, 0, Decimal("0")

def run(capability, params):
    """One call; counts it and what it was charged."""
    global calls, charged
    result = dx.call(capability, params)
    calls += 1
    charged += Decimal(str(result["meta"]["billing"]["amount"]))
    return result

import html
import os
import sqlite3
from datetime import datetime, timezone
from dataxapi import APIConnectionError, DataXAPIError

# The files are kept beside this script, wherever it is started from.
os.chdir(os.path.dirname(os.path.abspath(__file__)))

# 1. The accounts to follow: platform, any name you like, endpoint, account. Put your own here; each is one call a refresh.
ACCOUNTS = [
    ("Douyin", "Account A", "douyin.users.videos.list", {"id": "MS4wLjABAAAAZ0aPDJzFhBrs0q3wVsp2a9WWrBuAUMsVyygoaO0bCw8"}),
    ("Xiaohongshu", "Account B", "xiaohongshu.users.notes.list", {"id": "63bed214000000002702b862"}),
    ("WeChat", "Account C", "wechat_mp.accounts.articles.list", {"id": "gh_13c97ab93ce8"}),
]

# 2. Keep every post once, by platform and ID, with its latest counts. An account that fails is skipped; what the
#    others gave is kept.
db = sqlite3.connect("workbench.db")
db.execute("""create table if not exists posts (platform text, id text, account text, title text, url text,
    published_at text, likes integer, comments integer, first_seen text, primary key (platform, id))""")
now = datetime.now(timezone.utc).isoformat(timespec="seconds")
for platform, account, capability, params in ACCOUNTS:
    try:
        posts = run(capability, params)["data"]["items"]
    except (DataXAPIError, APIConnectionError) as error:
        print(f"skipped {account}: {error}")
        continue
    for post in posts:
        metrics = post.get("metrics") or {}
        db.execute("""insert into posts values (?, ?, ?, ?, ?, ?, ?, ?, ?) on conflict (platform, id) do update set
            likes = excluded.likes, comments = excluded.comments""",
            (platform, str(post.get("id") or post.get("url")), account, (post.get("title") or post.get("text") or "")[:80],
             post.get("url"), post.get("published_at"), metrics.get("likes"), metrics.get("comments"), now))
        fetched += 1
    db.commit()

# 3. A page for the browser and a CSV, newest first; the posts found for the first time are marked NEW.
COLUMNS = ["new", "platform", "account", "title", "url", "published_at", "likes", "comments", "id"]
rows = db.execute("""select case when first_seen = ? then 'NEW' else '' end, platform, account, title, url, published_at,
    likes, comments, id from posts order by published_at desc""", (now,)).fetchall()

def safe(value):
    """Text a spreadsheet would run as a formula is kept as text."""
    return f"'{value}" if isinstance(value, str) and value[:1] in ("=", "+", "-", "@", chr(9), chr(13)) else value

with open("posts.csv", "w", newline="", encoding="utf-8-sig") as file:
    csv.writer(file).writerows([COLUMNS, *([safe(value) for value in row] for row in rows)])

def cell(name, value):
    text = html.escape("" if value is None else str(value))
    is_link = name == "url" and text.startswith(("https://", "http://"))
    return f'<td><a href="{text}">open</a></td>' if is_link else f"<td>{text}</td>"

table = "".join("<tr>" + "".join(cell(name, value) for name, value in zip(COLUMNS, row)) + "</tr>" for row in rows)
with open("workbench.html", "w", encoding="utf-8") as file:
    file.write('<!doctype html><meta charset="utf-8"><title>Workbench</title>'
               "<style>body{font:14px system-ui;margin:24px}td,th{padding:6px 10px;border-bottom:1px solid #ddd;text-align:left}</style>"
               f"<h1>Workbench</h1><p>Refreshed {now}: {sum(row[0] == 'NEW' for row in rows)} new of {len(rows)}</p>"
               "<table><tr>" + "".join(f"<th>{name}</th>" for name in COLUMNS) + f"</tr>{table}</table>")

print(f"calls: {calls}, items: {fetched}, charged: ${charged}")
```

2026-11-29 真实跑过一次：调用 3 次，写出 89 行，扣费 $0.0420。失败的调用不收费。

## 用到的接口

- [抖音用户视频](https://dataxapi.com/zh/apis/douyin/users/videos/list/)
- [小红书用户笔记](https://dataxapi.com/zh/apis/xiaohongshu/users/notes/list/)
- [微信公众号文章列表](https://dataxapi.com/zh/apis/wechat_mp/accounts/articles/list/)

## 抖音的更多内容

- [抖音 API](https://dataxapi.com/zh/apis/douyin/)
- [小红书 API](https://dataxapi.com/zh/apis/xiaohongshu/)
- [微信公众号 API](https://dataxapi.com/zh/apis/wechat_mp/)
- [如何批量获取抖音关键词热度趋势](https://dataxapi.com/zh/guides/douyin-keyword-trends/)
- [如何批量导出抖音视频评论](https://dataxapi.com/zh/guides/douyin-video-comments/)
- [如何查询抖音星图达人报价](https://dataxapi.com/zh/guides/douyin-xingtu-creator-rates/)
- [抖音有 API 吗？用 Python 拉取视频和评论（2026）](https://dataxapi.com/zh/guides/douyin-api-python/)
- [抖音数据怎么导出？](https://dataxapi.com/zh/answers/export-douyin-data/)
- [抖音 sec_uid 是什么？和 uid、抖音号有什么区别？](https://dataxapi.com/zh/answers/douyin-sec-uid/)
- [抖音 aweme_id、modal_id 是什么？v.douyin.com 短链接怎么用？](https://dataxapi.com/zh/answers/douyin-aweme-id-modal-id/)
- [抖音搜索指数等于搜索次数吗？](https://dataxapi.com/zh/answers/douyin-search-index-vs-search-count/)
- [巨量算数关键词指数是什么、能拿到什么？](https://dataxapi.com/zh/answers/what-is-douyin-keyword-index-ocean-engine/)
- [抖音星图是什么？通过 API 能拿到哪些达人数据？](https://dataxapi.com/zh/answers/what-is-douyin-xingtu/)
- [抖音数据接口有哪些？第三方接口和开放平台的区别，能取什么（2026）](https://dataxapi.com/zh/answers/douyin-third-party-data-apis/)
- [抖音视频的播放地址（下载链接）怎么用 API 拿到？（2026）](https://dataxapi.com/zh/answers/douyin-video-play-url-api/)
- [哪个社媒数据接口最适合接给 AI？看一次返回占多少 token（2026）](https://dataxapi.com/zh/answers/social-media-api-for-ai-agents/)

---

目录修订号 ee799fed16791fcf。 [网页版](https://dataxapi.com/zh/guides/social-media-workbench/)
