调用captions.update时遭遇403 Forbidden错误求助
排查YouTube Captions API更新接口403权限错误
环境
- 语言:Python 3.10
- 库:google-api-python-client v2.x
- OAuth权限范围:
SCOPES = [ 'https://www.googleapis.com/auth/youtube.upload', 'https://www.googleapis.com/auth/youtube', 'https://www.googleapis.com/auth/youtube.force-ssl', 'https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/drive' ]
操作步骤
- 从token.pickle加载已保存的凭证,过期则自动刷新
- 构建YouTube服务实例:
from google.oauth2.credentials import Credentials from googleapiclient.discovery import build creds = Credentials.from_authorized_user_file('token.pickle', SCOPES) youtube = build('youtube', 'v3', credentials=creds)
- 调用captions.update接口:
request = youtube.captions().update( part='snippet', body={ 'id': '<CAPTION_TRACK_ID>', 'snippet': { 'language': 'en', 'name': 'English captions', 'isDraft': False } }, media_body=MediaFileUpload('captions_en.vtt', mimetype='text/vtt') ) response = request.execute() print(response)
错误信息
{ "error": { "code": 403, "message": "The permissions associated with the request are not sufficient to update the caption track. The request might not be properly authorized.", "errors": [ { "domain": "youtube.caption", "reason": "forbidden", "message": "The permissions associated with the request are not sufficient to update the caption track. The request might not be properly authorized.", "location": "id", "locationType": "parameter" } ] } }
已完成的排查
- 通过tokeninfo端点验证访问令牌包含youtube.force-ssl权限
- 删除token.pickle并重新执行OAuth流程获取新令牌
- 调用youtube.videos().list(mine=True)确认视频channelId与当前频道匹配
- 尝试改用captions.insert上传全新字幕而非更新现有轨道
- 确认目标视频无自动生成字幕轨道(此类轨道无法更新)
请求帮助
已完成上述排查仍收到403错误,是否存在其他需要配置的权限或参数(尤其针对非品牌频道)?
内容的提问来源于stack exchange,提问作者Kenji Ishikawa
相关产品推荐
相关产品推荐

