YouTube API CLI技能使用说明
2026-03-30
新闻来源:网淘吧
围观:16
电脑广告
手机广告
yt-api-cli
在终端中管理您的YouTube账户。一个完整的YouTube Data API v3命令行界面。
安装
# Using go install
go install github.com/nerveband/youtube-api-cli/cmd/yt-api@latest
# Or download from releases
curl -L -o yt-api https://github.com/nerveband/youtube-api-cli/releases/latest/download/yt-api-darwin-arm64
chmod +x yt-api
sudo mv yt-api /usr/local/bin/
设置
1. Google Cloud Console 设置
- 前往Google Cloud Console
- 创建/启用 YouTube Data API v3
- 创建 OAuth 2.0 凭据(桌面应用)
- 下载客户端配置
2. 配置 yt-api
mkdir -p ~/.yt-api
cat > ~/.yt-api/config.yaml << EOF
default_auth: oauth
default_output: json
oauth:
client_id: "YOUR_CLIENT_ID"
client_secret: "YOUR_CLIENT_SECRET"
EOF
3. 身份验证
yt-api auth login # Opens browser for Google login
yt-api auth status # Check auth state
命令
列表操作
# List your videos
yt-api list videos --mine
# List channel videos
yt-api list videos --channel-id UC_x5XG1OV2P6uZZ5FSM9Ttw
# List playlists
yt-api list playlists --mine
# List subscriptions
yt-api list subscriptions --mine
搜索
# Basic search
yt-api search --query "golang tutorial"
# With filters
yt-api search --query "music" --type video --duration medium --order viewCount
上传操作
# Upload video
yt-api upload video ./video.mp4 \
--title "My Video" \
--description "Description here" \
--tags "tag1,tag2" \
--privacy public
# Upload thumbnail
yt-api upload thumbnail ./thumb.jpg --video-id VIDEO_ID
播放列表管理
# Create playlist
yt-api insert playlist --title "My Playlist" --privacy private
# Add video to playlist
yt-api insert playlist-item --playlist-id PLxxx --video-id VIDxxx
频道操作
# Get channel info
yt-api list channels --id UCxxx --part snippet,statistics
# Update channel description
yt-api update channel --id UCxxx --description "New description"
输出格式
# JSON (default - LLM-friendly)
yt-api list videos --mine
# Table (human-readable)
yt-api list videos --mine -o table
# YAML
yt-api list videos --mine -o yaml
# CSV
yt-api list videos --mine -o csv > videos.csv
全局标志
| 标志 | 简称 | 描述 |
|---|---|---|
--output | -o | 输出格式:json(默认)、yaml、csv、表格 |
--quiet | -q | 抑制标准错误输出信息 |
--config | 配置文件路径 | |
--auth-type | 认证方式:oauth(默认)、service-account |
环境变量
| 变量 | 描述 |
|---|---|
YT_API_AUTH_TYPE | 认证方式:oauth 或 service-account |
YT_API_OUTPUT | 默认输出格式 |
YT_API_CLIENT_ID | OAuth 客户端 ID |
YT_API_CLIENT_SECRET | OAuth 客户端密钥 |
YT_API_CREDENTIALS | 服务账户 JSON 文件路径 |
认证方法
OAuth 2.0(默认)
最适合交互式使用及访问个人YouTube账户。

yt-api auth login # Opens browser
服务账户
最适合服务器端自动化。
yt-api --auth-type service-account --credentials ./key.json list videos
快速诊断命令
yt-api info # Full system state
yt-api info --test-connectivity # Verify API access
yt-api info --test-permissions # Check credential capabilities
yt-api auth status # Authentication details
yt-api version # Version info
错误处理
退出代码:
0- 成功1- 常规错误2- 认证错误3- API错误(配额、权限)4- 输入错误
针对大型语言模型与自动化
- 默认输出JSON格式
- 结构化错误以JSON对象呈现
--quiet解析模式--dry-run仅验证而不执行- 支持标准输入以传输数据
备注
- 需要启用YouTube Data API v3的有效Google Cloud凭据
- OAuth令牌存储在
~/.yt-api/tokens.json(权限为0600) - 默认输出为JSON格式(针对LLM优化)
- 支持所有YouTube Data API v3资源
来源
文章底部电脑广告
手机广告位-内容正文底部


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