Youtube Data
YouTube 数据
通过以下方式访问 YouTube 数据:TranscriptAPI.com—— 一个轻量级的谷歌 YouTube 数据 API 替代方案。
设置
如果$TRANSCRIPT_API_KEY未设置,帮助用户创建一个账户(100 免费点数,无需信用卡):
步骤 1 — 注册:向用户询问他们的邮箱。
node ./scripts/tapi-auth.js register --email USER_EMAIL
→ OTP 已发送至邮箱。询问用户:"请检查您的邮箱,查看 6 位验证码。"
步骤 2 — 验证:一旦用户提供了 OTP:
node ./scripts/tapi-auth.js verify --token TOKEN_FROM_STEP_1 --otp CODE
API 密钥将保存至
~/.openclaw/openclaw.json。详情请参见下方的文件写入。修改前会备份现有文件。
手动选项:transcriptapi.com/signup→ 仪表板 → API 密钥。
文件写入
verify 和 save-key 命令会将 API 密钥保存到~/.openclaw/openclaw.json(设置skills.entries.transcriptapi.apiKey和enabled: true)。修改前,现有文件会备份到~/.openclaw/openclaw.json.bak。
要在代理之外的终端/CLI 中使用 API 密钥,请手动添加到您的 shell 配置文件中:export TRANSCRIPT_API_KEY=<您的密钥>
API 参考
完整 OpenAPI 规范:transcriptapi.com/openapi.json— 请查阅此文件以获取最新的参数和模式。
视频数据(转录文本 + 元数据) — 1 积分
curl -s "https://transcriptapi.com/api/v2/youtube/transcript\
?video_url=VIDEO_URL&format=json&include_timestamp=true&send_metadata=true" \
-H "Authorization: Bearer $TRANSCRIPT_API_KEY"
响应:
{
"video_id": "dQw4w9WgXcQ",
"language": "en",
"transcript": [
{ "text": "We're no strangers to love", "start": 18.0, "duration": 3.5 }
],
"metadata": {
"title": "Rick Astley - Never Gonna Give You Up",
"author_name": "Rick Astley",
"author_url": "https://www.youtube.com/@RickAstley",
"thumbnail_url": "https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg"
}
}
搜索数据 — 1 积分
curl -s "https://transcriptapi.com/api/v2/youtube/search?q=QUERY&type=video&limit=20" \
-H "Authorization: Bearer $TRANSCRIPT_API_KEY"
视频结果字段: videoId标题频道ID频道标题频道句柄频道已验证时长文本观看次数文本发布时间文本是否有字幕缩略图频道结果字段(类型=频道):频道ID标题,hasCaptions,thumbnails
Channel result fields(type=channel):channelId,title,handle,url,description,subscriberCount,verified,rssUrl,thumbnails
频道数据
频道端点接受频道— 一个@handle、频道URL,或UC...ID。无需预先解析。
将句柄解析为ID(免费):
curl -s "https://transcriptapi.com/api/v2/youtube/channel/resolve?input=@TED" \
-H "Authorization: Bearer $TRANSCRIPT_API_KEY"
返回:{"channel_id": "UCsT0YIqwnpJCM-mx7-gSA4Q", "resolved_from": "@TED"}
最近15个视频的精确统计数据(免费):
curl -s "https://transcriptapi.com/api/v2/youtube/channel/latest?channel=@TED" \
-H "Authorization: Bearer $TRANSCRIPT_API_KEY"
返回:channelinfo,resultsarray withvideoId,title,published(ISO),viewCount(精确数字),description,thumbnail
所有频道视频(分页,每页1积分):
curl -s "https://transcriptapi.com/api/v2/youtube/channel/videos?channel=@NASA" \
-H "Authorization: Bearer $TRANSCRIPT_API_KEY"
每页返回100个视频 +continuation_token用于分页。
频道内搜索(1积分):
curl -s "https://transcriptapi.com/api/v2/youtube/channel/search\
?channel=@TED&q=QUERY&limit=30" \
-H "Authorization: Bearer $TRANSCRIPT_API_KEY"
播放列表数据 — 每页1积分
接受playlist— YouTube播放列表URL或播放列表ID。
curl -s "https://transcriptapi.com/api/v2/youtube/playlist/videos?playlist=PL_ID" \
-H "Authorization: Bearer $TRANSCRIPT_API_KEY"
返回:results(视频),播放列表信息(标题,视频数量,所有者名称,观看次数),继续令牌,还有更多
积分成本
| 端点 | 成本 | 返回的数据 |
|---|---|---|
| 转录稿 | 1 | 完整转录稿 + 元数据 |
| 搜索 | 1 | 视频/频道详情 |
| 频道/解析 | 免费 | 频道ID映射 |
| 频道/最新 | 免费 | 15个视频 + 精确统计数据 |
| 频道/视频 | 1/页 | 每页100个视频 |
| 频道/搜索 | 1 | 匹配查询的视频 |
| 播放列表/视频 | 1/页 | 每页100个视频 |
错误
| 代码 | 操作 |
|---|---|
| 402 | 无点数 — transcriptapi.com/billing |
| 404 | 未找到 |
| 408 | 超时 — 重试一次 |
| 422 | 参数格式无效 |
免费等级:100点数,300次请求/分钟。


微信扫一扫,打赏作者吧~