# 用 Python 获取 YouTube 视频评论

传视频 ID，用 `data.next` 每页 20 条往下翻。10 页 200 条评论，10 次调用、$0.02，不用建 Google Cloud 项目，不用 OAuth，也没有每日配额。

更新于 2026-11-22

## 翻完全部评论

`id` 填 youtube.com 链接里 `v=` 后面的值，或者 `youtu.be/` 后面那段。下一页的令牌很长，放在 `data.next` 里原样传回。

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

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

```python
import requests

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

params = {"id": "CLsCU_JX1eU"}
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/youtube/comments/list";
const HEADERS = { Authorization: "Bearer YOUR_API_KEY" };

let params = {"id":"CLsCU_JX1eU"};
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": "xxxxxxxx035xxx8xx2x0xxxxxx",
        "text": "Example text",
        "author": {
          "id": "xx_xxxxxxxxxxxxxxx5x99xx",
          "name": "Example name",
          "avatar": "https://example.com/image.jpg"
        },
        "likeCount": 60,
        "replyCount": 14
      },
      {
        "id": "xxxx2xxxxxxxxxxx9x40xxxxxx",
        "text": "Example text",
        "author": {
          "id": "xxxxxxxxx8xx7xx3xxxxxxxx",
          "name": "Example name",
          "avatar": "https://example.com/image.jpg"
        },
        "likeCount": 1530,
        "replyCount": 79
      }
    ],
    "has_more": true,
    "next": {
      "cursor": "Eg0SC0NMc0NV…"
    }
  },
  "meta": {
    "request_id": "example",
    "endpoint": "youtube.comments.list",
    "normalized": true,
    "unavailable": [
      "createdAt"
    ],
    "billing": {
      "charged": true,
      "amount": 0.002,
      "balance": 4.98
    }
  }
}
```

## 这个例子花多少钱

| 步骤 | 调用次数 | 单价 | 小计 |
| --- | --- | --- | --- |
| 评论，10 页、每页 20 条 | 10 | $0.002 | $0.02 |
| 合计 | 10 | | $0.02 |

## 要注意的地方

- 2026-11-22 实测每页 20 条，第二页没有重复。
- 传 `sort_by` 在热门评论和最新评论之间切换。
- 回复要单独取：`youtube.comment_replies.list`。
- 官方 YouTube Data API v3 每取一页 commentThreads 扣 1 个配额单位，每天 10,000 个；这里没有配额，只按次计价。

## 用到的接口

- [YouTube 视频评论](https://xtikapi.com/zh/apis/youtube/comments/list): $0.002 / 次

## YouTube的更多内容

- [yt-dlp 抓 YouTube 报“not a bot”或评论 Incomplete data 中断怎么办](https://xtikapi.com/zh/answers/yt-dlp-sign-in-to-confirm-not-a-bot)
- [YouTube commentThreads.list 报 403 commentsDisabled 是什么意思](https://xtikapi.com/zh/answers/youtube-api-comments-disabled-403)
- [YouTube 视频评论怎么批量导出](https://xtikapi.com/zh/answers/youtube-comments-export)
- [YouTube Data API 每天 10000 配额不够用怎么办](https://xtikapi.com/zh/answers/youtube-api-quota-alternative)

## 常见问题

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

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

### 这是官方的 YouTube Data API 吗？

不是。它读取视频页上公开显示的评论，所以不需要 Google API key 和配额；返回格式和本站其他平台的评论一样。

---

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