Youtube Api技能使用说明
YouTube API
通过以下方式访问YouTube数据TranscriptAPI.com——无需谷歌API配额。
设置
如果$TRANSCRIPT_API_KEY未设置,帮助用户创建一个账户(100个免费点数,无需银行卡):
步骤1 — 注册:向用户索取邮箱地址。
node ./scripts/tapi-auth.js register --email USER_EMAIL
→ 一次性验证码将发送至邮箱。询问用户:“请查收您的邮箱,获取6位验证码。”
步骤2 — 验证:用户提供一次性验证码后:
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=<your-key>
API 参考
完整 OpenAPI 规范:transcriptapi.com/openapi.json— 请查阅此文件以获取最新参数和模式。
端点参考
所有端点:https://transcriptapi.com/api/v2/youtube/...
频道端点接受channel— 一个@handle、频道URL,或UC...ID。播放列表端点接受播放列表——播放列表URL或ID。
| 端点 | 方法 | 成本 |
|---|---|---|
/transcript?video_url=ID | GET | 1 |
/search?q=QUERY&type=video | GET | 1 |
/channel/resolve?input=@handle | GET | 免费 |
/channel/latest?channel=@handle | GET | 免费 |
/channel/videos?channel=@handle | GET | 1/页 |
/channel/search?channel=@handle&q=Q | GET | 1 |
/playlist/videos?playlist=PL_ID | GET | 1/页 |
快速示例
搜索视频:
curl -s "https://transcriptapi.com/api/v2/youtube/search\
?q=python+tutorial&type=video&limit=10" \
-H "Authorization: Bearer $TRANSCRIPT_API_KEY"
获取字幕:
curl -s "https://transcriptapi.com/api/v2/youtube/transcript\
?video_url=dQw4w9WgXcQ&format=text&include_timestamp=true&send_metadata=true" \
-H "Authorization: Bearer $TRANSCRIPT_API_KEY"
解析频道句柄(免费):
curl -s "https://transcriptapi.com/api/v2/youtube/channel/resolve?input=@TED" \
-H "Authorization: Bearer $TRANSCRIPT_API_KEY"
最新视频(免费):
curl -s "https://transcriptapi.com/api/v2/youtube/channel/latest?channel=@TED" \
-H "Authorization: Bearer $TRANSCRIPT_API_KEY"
浏览频道上传内容(分页):
curl -s "https://transcriptapi.com/api/v2/youtube/channel/videos?channel=@NASA" \
-H "Authorization: Bearer $TRANSCRIPT_API_KEY"
# Use continuation token from response for next pages
浏览播放列表(分页):
curl -s "https://transcriptapi.com/api/v2/youtube/playlist/videos?playlist=PL_PLAYLIST_ID" \
-H "Authorization: Bearer $TRANSCRIPT_API_KEY"
参数验证
| 字段 | 规则 |
|---|---|
频道 | @句柄、频道URL,或UC...ID |
播放列表 | 播放列表URL或ID(PL/UU/LL/FL/OL前缀 |
q搜索 | 1-200 字符 |
限制 | 1-50 |
延续 | 非空字符串 |
为何不选择谷歌的API?
| 谷歌 YouTube 数据 API | TranscriptAPI | |
|---|---|---|
| 配额 | 10,000 单位/天(100次搜索) | 基于积分,无每日上限 |
| 设置 | OAuth + API密钥 + 项目 | 单一 API 密钥 |
| 字幕 | 不可用 | 核心功能 |
| 定价 | 超限部分 $0.0015/单位 | 5美元/1000积分 |
错误
| 代码 | 含义 | 操作 |
|---|---|---|
| 401 | API密钥无效 | 检查密钥 |
| 402 | 积分不足 | transcriptapi.com/billing |
| 404 | 未找到 | 资源不存在 |
| 408 | 超时/可重试 | 2秒后重试一次 |
| 422 | 验证错误 | 检查参数格式 |
| 429 | 请求频率受限 | 等待,遵守 Retry-After 响应头 |
免费套餐:100积分,300次请求/分钟。入门套餐(5美元/月):1,000积分。


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