YouTube 评论, 不撞配额墙
完整评论串以带类型的 JSON 返回,不用算每天的配额,也不会只拉回一半。
团队为什么选它
拉够 100 次,撞墙
YouTube Data API v3 给每个 Google Cloud 项目每天 10,000 units,单次 commentThreads.list 调用就扣 100 units。算下来一天只能拉 100 页评论,然后就到顶了。
一条视频,两天半
一条有 5,000 条评论的视频,按每页 20 条算是 250 页,全拉一遍要 25,000 units——一条视频吃掉两天半配额。换成 10 条视频,排期就得按周算,不是按小时。
重置时间不管你的日程
官方配额在太平洋时间零点才回。晚上 11 点撞顶,管道就得干等几个小时——什么时候接着干,由重置时钟说了算,不是你的截止时间。
越用越糟的绕法
多开几个 Google Cloud 项目轮着用,能撑到 Google 认出这个套路为止;找卖 key 的服务,则是把你手上所有 key 一起押上。根子上的问题没变:官方 API 是为展示做的,不是为批量读取做的。
没有按天的配额要盘算
Anysite 不碰 YouTube Data API,直接读公开可见的评论数据,返回带类型的 JSON。credits 按月重置,套餐每月 $30 起。
回复串装在同一个响应里
每页 1 credit,至多 100 条评论,replies[] 一起带回来,不用另发请求,也不扣额外 units。每条评论都带 id、author、author_id、text、like_count、reply_count 和 published_at。
怎么用
拿把 key,跳过控制台
注册,复制 token。不用走 OAuth,不用开 Google Cloud 项目,也不用申请 YouTube API key:每次请求靠一个 access-token 请求头鉴权。
提交一个 video ID
带上 video_id,向 /api/youtube/video/comments 发一次 POST。count 至多设到每页 100 条,sort_order 设成「top」或「new」,一个来回头一页就回来了。
POST /api/youtube/video/comments · {"video_id": "…", "count": 100}
跟着游标翻到底
每个响应都带 has_more 和 next_cursor。把游标传回去,直到 has_more 变成 false;回复串跟在同样的页里回来,不额外扣 credits。
装进你干活的地方
每页都是带类型的 JSON,直接落进 CSV、数仓表或智能体的上下文:做情绪分析、受众研究、训练集都行。分析交给你的工具,Anysite 只做下面那层数据层。
复制、粘贴、把评论串拉下来
curl -X POST "https://api.anysite.io/api/youtube/video/comments" \
-H "access-token: YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"video_id": "VIDEO_ID", "count": 100, "sort_order": "top"}'一次 POST,至多回 100 条热门评论;token 和 video id 是占位符。
import requests
URL = "https://api.anysite.io/api/youtube/video/comments"
headers = {"access-token": "YOUR_TOKEN", "Content-Type": "application/json"}
comments, cursor = [], None
while True:
payload = {"video_id": "VIDEO_ID", "count": 100, "sort_order": "top"}
if cursor:
payload["cursor"] = cursor
data = requests.post(URL, headers=headers, json=payload).json()
comments.extend(data["comments"])
if not data.get("has_more"):
break
cursor = data["next_cursor"]文档里的游标循环,删减版:一直跑到 has_more 变成 false,每页 1 credit。
{
"comments": [
{
"id": "UgxABC123_comment_xyz",
"author": "username_display",
"text": "The full comment text including line breaks.",
"like_count": 142,
"reply_count": 7,
"published_at": "2024-11-15T09:33:00Z",
"replies": [
{ "id": "UgxABC123_comment_xyz.reply1", "author": "another_user", "like_count": 12 }
]
}
],
"total_comments": 48291,
"has_more": true,
"next_cursor": "eyJwYWdlIjoyLCJ0b2tlbiI6Ii4uLiJ9"
}从线上示例响应删减而来:author_id 和回复正文也会返回,total_comments 是该视频的评论总数。
常见问题
官方配额按 unit 算,每天太平洋时间零点重置:每次评论列表请求扣 100 units,一天总共 10,000 units,也就是 100 次。Anysite 没有按天的上限,套餐是按一个月的真实工作量配的,每月 $30 起。