> ## Documentation Index
> Fetch the complete documentation index at: https://docs.querying.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# TikTok API

> 搜索 TikTok 视频，并以 JSON 读取视频、含回复的评论、创作者和热门视频，包括播放、点赞、分享、收藏、评论数和发布时间。

通过 `POST /v1/social/tiktok/{action}` 以 JSON 读取公开的 TikTok 数据。用 `{action}` 选择要读取的内容。每次完成的请求消耗 **0.5 积分**。

## 请求

```bash theme={"theme":"css-variables"}
curl -X POST https://api.querying.ai/v1/social/tiktok/search \
  -H "Authorization: Bearer $QUERYING_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "query": "coffee recipe", "limit": 1 }'
```

请求最多等待结果 290 秒，并以 `200` 应答，结果在 `response` 中。仍在运行的任务以 `202` 应答，请轮询 `GET /v1/async/task/{id}` 或设置 `webhook`；参见[异步任务](https://docs.querying.ai/zh/concepts/async-tasks.md)。

## 操作

| 路径 | 读取内容 | 必填 |
| - | - | - |
| `/v1/social/tiktok/search` | 按关键词找到的视频 | `query` |
| `/v1/social/tiktok/video` | 一个视频 | `videoId` 或 `url` |
| `/v1/social/tiktok/comments` | 视频的评论及其回复 | `videoId` 或 `url` |
| `/v1/social/tiktok/creator` | 创作者的个人主页 | `username` 或 `url` |
| `/v1/social/tiktok/trending` | 某个国家的热门视频 | 无 |

对于 `video` 和 `comments`，`videoId` 和 `url` 接受视频 ID、视频或图文帖子的 URL，或 `vm.tiktok.com`、`vt.tiktok.com` 短链接。对于 `creator`，`username` 和 `url` 接受用户名、`@username` 或个人主页 URL，例如 `https://www.tiktok.com/@nasa`。

## 参数

请求中如有其他操作的参数、下列以外的值或缺少必填字段，会在提交时被拒绝，并返回指明该字段的 `400 VALIDATION_ERROR`。

`search`：

* `query`：必填，最多 500 个字符，且至少包含一个字母或数字。
* `limit`：可选，1 到 50 的整数，默认 10。搜索通过 Google 结果查找视频，因此最多返回 `limit` 个视频，Google 列出的较少时返回更少。只返回一页。

`comments`：

* `limit`：可选，1 到 500 的整数，默认 50。评论和回复合并计数。
* `includeReplies`：`true`（默认）会在每条评论之后读取它的回复；`false` 只返回顶层评论。

`trending`：

* `limit`：可选，1 到 50 的整数，默认 20。
* `regionCode`：两位国家代码，默认 `US`。

## 响应示例

```json theme={"theme":"css-variables"}
{
  "platform": "tiktok",
  "action": "search",
  "query": "coffee recipe",
  "videos": [
    {
      "url": "https://www.tiktok.com/@starbucks/video/7689165576589069582",
      "music": {
        "id": "7689165597564750605",
        "title": "original sound - Starbucks",
        "author": "Starbucks",
        "original": true,
        "durationSeconds": 7
      },
      "author": {
        "id": "6717391402571039749",
        "handle": "starbucks",
        "verified": true,
        "profileUrl": "https://www.tiktok.com/@starbucks",
        "displayName": "Starbucks",
        "followerCount": 3600000
      },
      "region": "US",
      "source": "web",
      "caption": "same fresh cup of coffee, different day",
      "videoId": "7689165576589069582",
      "language": "en",
      "position": 1,
      "likeCount": 3861,
      "viewCount": 551300,
      "shareCount": 86,
      "publishedAt": "2026-09-24T18:09:35.000Z",
      "collectCount": 234,
      "commentCount": 87,
      "durationSeconds": 7
    }
  ],
  "hasMore": false,
  "provider": "tiktok_web",
  "nextCursor": null,
  "returnedCount": 1
}
```

## 结果字段

* 每个响应都会原样返回 `platform` 和 `action`，`provider` 表示数据的读取来源。列表带有 `returnedCount`。
* 视频包含 `videoId`、`url`、`caption`、`hashtags`（说明文字中有标签时）、`author`（`id`、`handle`、`displayName`、`verified`、`avatarUrl`、`profileUrl`、`followerCount`）、`music`（`id`、`title`、`author`、`original`、`durationSeconds`）、`coverUrl`、`durationSeconds`、`language`、`region`、`publishedAt`、`viewCount`、`likeCount`、`commentCount`、`shareCount`，以及表示被收藏次数的 `collectCount`。超过 100 万的数值是 TikTok 显示的四舍五入值。
* `search` 返回 `videos`，每个视频带有 `position` 和 `source`；`hasMore` 为 `false`，`nextCursor` 为 `null`。页面未能读取的结果只包含 `url`、`videoId` 以及作者的 `handle` 和 `profileUrl`。
* `video` 在顶层返回视频的字段。
* `comments` 返回 `videoId`、`url`（只发送 `videoId` 时为 `null`）、`comments`、`includeReplies`、`returnedCount`、`topLevelCount`、`replyCount`，以及 TikTok 为该视频显示的评论数 `availableTopLevelCount`。
  * 评论包含 `commentId`、`videoId`、`text`、`author`、`likeCount`、`replyCount`、`publishedAt` 和 `parentId`；顶层评论的该值为 `null`，回复的该值为它所回复评论的 `commentId`。
  * 没有评论或已关闭评论的视频会使任务以 `ENGINE_NO_RESULT` 结束。
* `creator` 返回 `creatorId`、`handle`、`displayName`、`bio`、`bioLink`、`avatarUrl`、`profileUrl`、`verified`、`privateAccount`、`createdAt`、`followerCount`、`followingCount`、`likeCount` 和 `videoCount`。
* `trending` 返回 `videos` 和所读取的 `regionCode`。
* 不存在或私密的视频或创作者会使任务以 `PAGE_UNAVAILABLE` 结束。只对完成的请求计费。

## HTML 页面

将 `include.html` 设为 `true`，结果会增加 `html`，即回答所读取的 TikTok 页面的链接，页面保存为可放进报告的文件。`html` 包含 `status`、`url` 和 `expiresAt`，说明见 [HTML 页面](https://docs.querying.ai/zh/engines/html-pages.md)。

* `include.html` 适用于 `video` 和 `creator`。
* 文件是 TikTok 为该页面发送的 HTML 文档，即脚本运行之前的状态。文件以一条备注注释开头，`Saved by querying.ai: the page TikTok served for task <id> at <UTC time>, the page as TikTok sent it, before any script ran, the address of the visit and its session ids masked.`
* 属于本次访问的值会替换为等长的零：Cookie 值、会话、请求和设备 ID、CSRF 及其他令牌、nonce，以及媒体地址中的签名。由于这些签名已被遮蔽，文件中的图片和视频链接无法加载。取决于访问来源的内容，例如媒体地址中的区域 CDN 主机名，保持 TikTok 发送时的样子。
* 文档的脚本以文本形式保留在文件中。提供该文件时会附带 Content-Security-Policy，不运行任何脚本，也不加载任何外部资源。
* TikTok 把数据放在内嵌的 JSON 脚本中发送，因此打开的文件几乎什么都不显示，数据在文档源码中。
* 在 `video` 上，短链接会保留为它重定向到的页面。
* 其他所有操作（`search`、`comments` 和 `trending`）会在提交任务时返回 `422 EVIDENCE_UNSUPPORTED`，错误信息会说明原因。
* 页面不额外收费，请求仍为 0.5 积分。
* 无法保存页面时，仍会返回回答，`html` 为 `{ "status": "failed", "error": "EVIDENCE_FAILED" }`。重新提交任务即可再次尝试。

## 相关

* [Instagram](https://docs.querying.ai/zh/engines/instagram.md)
* [YouTube](https://docs.querying.ai/zh/engines/youtube.md)
* [TikTok 广告](https://docs.querying.ai/zh/engines/tiktok-ads.md)，广告主在 TikTok 上投放的广告
* [引擎概览](https://docs.querying.ai/zh/engines/overview.md)
* [积分与限制](https://docs.querying.ai/zh/concepts/credits-and-limits.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.