# 用 Python 批量获取 TikTok 视频评论

先用一次搜索找到视频，再按每页约 20 条翻完评论。实测 10 页拿到 200 条评论，加上搜索共 11 次调用，$0.022。

更新于 2026-11-22

## 第 1 步：找到视频

按关键词搜索 TikTok，每条结果的 `id` 就是评论接口要的视频 ID。手上已经有视频链接的话可以跳过，链接里 `/video/` 后面那串数字就是 ID。

[TikTok 视频搜索](https://xtikapi.com/zh/apis/tiktok/videos/search): `GET /v1/tiktok/videos/search`, $0.002 / 次

```bash
curl "https://xtikapi.com/v1/tiktok/videos/search?keyword=camping+coffee" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

```python
import requests

response = requests.get("https://xtikapi.com/v1/tiktok/videos/search", params={"keyword": "camping coffee"}, headers={"Authorization": "Bearer YOUR_API_KEY"}, timeout=60)
response.raise_for_status()
print(response.json()["data"])
```

```javascript
const URL = "https://xtikapi.com/v1/tiktok/videos/search";
const HEADERS = { Authorization: "Bearer YOUR_API_KEY" };

const response = await fetch(`${URL}?${new URLSearchParams({"keyword":"camping coffee"})}`, { headers: HEADERS });
const { data } = await response.json();
console.log(data);
```

录制的真实返回（列表只保留前两条）：

```json
{
  "data": {
    "items": [
      {
        "id": "0779509297655120597",
        "url": "https://example.com/link",
        "text": "Example text",
        "author": {
          "id": "xx1xxxxxxxxxxx-xxxxxxxxxxxx5xxxx37x9x6xxx_xxxxxx76xxxxxxxxxxx0xxx30x02xxxxx2",
          "username": "example_user",
          "name": "Example name",
          "avatar": "https://example.com/image.jpg",
          "followers": 118728
        },
        "createdAt": "2026-11-07T13:41:13.000Z",
        "likeCount": 257030,
        "commentCount": 385,
        "shareCount": 24319,
        "viewCount": 2152698,
        "cover": "https://example.com/image.jpg"
      },
      {
        "id": "0776986179814197990",
        "url": "https://example.com/link",
        "text": "Example text",
        "author": {
          "id": "xx1xxxxxxxxx5xxxxxxxxxxx7xxx0xxxxxxx4-xxxxxxxxxxxxxxxx55xxxxx5x0xxxxxxxx9xxx",
          "username": "example_user",
          "name": "Example name",
          "avatar": "https://example.com/image.jpg",
          "followers": 53345
        },
        "createdAt": "2026-10-31T12:06:19.000Z",
        "likeCount": 625844,
        "commentCount": 1046,
        "shareCount": 63850,
        "viewCount": 8935392,
        "cover": "https://example.com/image.jpg"
      }
    ],
    "has_more": true,
    "next": {
      "cursor": 20
    }
  },
  "meta": {
    "request_id": "example",
    "endpoint": "tiktok.videos.search",
    "normalized": true,
    "unavailable": [],
    "billing": {
      "charged": true,
      "amount": 0.002,
      "balance": 4.98
    }
  }
}
```

## 第 2 步：翻完每一页评论

把视频 ID 传给 `id`。每页约 20 条，循环把 `data.next` 加到参数里，直到它为 null。每一页算一次调用。

[TikTok 视频评论](https://xtikapi.com/zh/apis/tiktok/comments/list): `GET /v1/tiktok/comments/list`, $0.002 / 次

```bash
curl "https://xtikapi.com/v1/tiktok/comments/list?id=7708408003065580831" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

```python
import requests

URL = "https://xtikapi.com/v1/tiktok/comments/list"
HEADERS = {"Authorization": "Bearer YOUR_API_KEY"}

params = {"id": "7708408003065580831"}
items = []
for _ in range(10):  # one call per page
    for attempt in range(3):  # 5xx errors are not charged: retry
        response = requests.get(URL, params=params, headers=HEADERS, timeout=60)
        if response.status_code < 500:
            break
    response.raise_for_status()
    data = response.json()["data"]
    items += data["items"]
    if not data.get("next"):  # null on the last page
        break
    params.update(data["next"])

print(len(items), "items")
```

```javascript
const URL = "https://xtikapi.com/v1/tiktok/comments/list";
const HEADERS = { Authorization: "Bearer YOUR_API_KEY" };

let params = {"id":"7708408003065580831"};
const items = [];
for (let page = 0; page < 10; page++) {
  let response;
  for (let attempt = 0; attempt < 3; attempt++) {
    // 5xx errors are not charged: retry
    response = await fetch(`${URL}?${new URLSearchParams(params)}`, { headers: HEADERS });
    if (response.status < 500) break;
  }
  if (!response.ok) throw new Error(`HTTP ${response.status}`);
  const { data } = await response.json();
  items.push(...data.items);
  if (!data.next) break; // null on the last page
  params = { ...params, ...data.next };
}
console.log(items.length, "items");
```

录制的真实返回（列表只保留前两条）：

```json
{
  "data": {
    "items": [
      {
        "id": "0772508255858426293",
        "text": "Example text",
        "author": {
          "id": "xx1xxxxxxxxx8xxx1xxxxxxxxxxxxxxxxxxxxx_xxxx7xx4xxxx3xxxxxxxxxxxxxxxxxxxxxx0x",
          "username": "example_user",
          "name": "Example name",
          "avatar": "https://example.com/image.jpg",
          "followers": 0,
          "description": "Example text"
        },
        "createdAt": "2026-11-15T15:38:44.000Z",
        "likeCount": 349,
        "replyCount": 5
      },
      {
        "id": "0773410572235817260",
        "text": "Example text",
        "author": {
          "id": "xx1xxxxxxxxxxx5xxxxxxxxx653x-1x2xx2xx8xxxx4xxx_xxxxxx1xx4xxxxxx5xxx7xxxxxx1x",
          "username": "example_user",
          "name": "Example name",
          "avatar": "https://example.com/image.jpg",
          "followers": 0,
          "description": "Example text"
        },
        "createdAt": "2026-11-18T02:39:24.000Z",
        "likeCount": 2,
        "replyCount": 0
      }
    ],
    "has_more": true,
    "next": {
      "cursor": 20
    }
  },
  "meta": {
    "request_id": "example",
    "endpoint": "tiktok.comments.list",
    "normalized": true,
    "unavailable": [],
    "billing": {
      "charged": true,
      "amount": 0.002,
      "balance": 4.98
    }
  }
}
```

## 这个例子花多少钱

| 步骤 | 调用次数 | 单价 | 小计 |
| --- | --- | --- | --- |
| 找视频（搜索 1 次） | 1 | $0.002 | $0.002 |
| 评论，10 页、每页约 20 条 | 10 | $0.002 | $0.02 |
| 合计 | 11 | | $0.022 |

## 要注意的地方

- 2026-11-22 实测每页 20 条评论。
- 不含楼中楼回复，要的话用 `tiktok.comment_replies.list`，传视频 `id` 和评论的 `id`（作为 `comment_id`）。
- 两次调用之间可能有新评论进来，合并多页时按 `id` 去重。

## 用到的接口

- [TikTok 视频搜索](https://xtikapi.com/zh/apis/tiktok/videos/search): $0.002 / 次
- [TikTok 视频评论](https://xtikapi.com/zh/apis/tiktok/comments/list): $0.002 / 次

## TikTok的更多内容

- [TikTok-Api 常见报错与 statusCode 速查：EmptyResponseException、200 空返回、验证码](https://xtikapi.com/zh/answers/tiktok-api-errors-and-fixes)
- [TikTok 评论接口用不了怎么办](https://xtikapi.com/zh/answers/tiktok-comments-api-not-working)
- [TikTok 话题标签下的视频怎么批量获取](https://xtikapi.com/zh/answers/tiktok-hashtag-videos-api)
- [TikTok Display API 能读别人的视频吗](https://xtikapi.com/zh/answers/tiktok-display-api-other-users)
- [TikTok Research API 能商用吗](https://xtikapi.com/zh/answers/tiktok-research-api-commercial-use)

## 常见问题

### 用 XTikAPI 做这件事要花多少钱？

按本文的例子是 11 次调用，共 $0.022。失败和超时不收费；验证过邮箱的新账号送 $0.50 试用额度。

### 需要申请 TikTok Research API 吗？

不需要。用本站的 API key 直接读公开评论，没有申请和审核。

---

XTikAPI: one API key for public social media data, prepaid per call. [HTML version](https://xtikapi.com/zh/guides/tiktok-video-comments-python) · [llms.txt](https://xtikapi.com/llms.txt) · [OpenAPI](https://xtikapi.com/openapi.json)
