无法创建YouTube内容所有者预估收入批量报告?权限被拒且已获所有授权
问题描述
尝试通过YouTube Reporting API创建content_owner_estimated_revenue_a1类型的批量报告任务时,收到403权限拒绝错误:
'error': {'code': 403, 'message': 'The caller does not have permission', 'status': 'PERMISSION_DENIED'}
当前OAuth令牌的授权范围如下:
"scopes": ["https://www.googleapis.com/auth/userinfo.email, https://www.googleapis.com/auth/yt-analytics.readonly, https://www.googleapis.com/auth/yt-analytics-monetary.readonly, https://www.googleapis.com/auth/youtube.readonly"]
执行的请求代码:
Python代码片段
response = self.session.request( method='POST', url='https://youtubereporting.googleapis.com/v1/jobs', headers={ 'Accept': 'application/json', 'Authorization': 'Bearer ' + self.token, }, json={ 'reportTypeId': 'content_owner_estimated_revenue_a1', 'name': 'content_owner_estimated_revenue_a1', }, )
Curl命令
curl -X POST \ https://youtubereporting.googleapis.com/v1/jobs \ -H 'Accept: application/json' \ -H 'Authorization: Bearer <TOKEN>' \ -H 'Content-Type: application/json' \ -d '{ "reportTypeId": "content_owner_estimated_revenue_a1", "name": "content_owner_estimated_revenue_a1" }'
解决方案
你遗漏了两个关键配置,按以下步骤排查修复:
添加YouTube Reporting API的授权范围
你调用的是YouTube Reporting API的端点,但当前令牌的授权范围里没有该API的权限。创建报告任务需要添加https://www.googleapis.com/auth/yt-reporting范围(该权限允许创建/管理报告任务),更新后的授权范围列表应为:"scopes": [ "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/yt-analytics.readonly", "https://www.googleapis.com/auth/yt-analytics-monetary.readonly", "https://www.googleapis.com/auth/youtube.readonly", "https://www.googleapis.com/auth/yt-reporting" ]注意:更新范围后需要重新生成OAuth令牌,旧令牌不会自动包含新权限。
确认授权账号的内容所有者权限
content_owner_estimated_revenue_a1是面向**YouTube内容所有者(MCN/品牌账号管理者)**的报告,普通频道账号无法访问:- 确保你用来生成OAuth令牌的账号,已被添加为目标内容所有者的授权管理员(在YouTube Studio的「内容所有者设置」中配置);
- 登录该账号,确认能在YouTube Studio中访问内容所有者的后台数据,而非仅单个频道的数据。
额外检查
若仍报错,确认你的Google Cloud项目已启用YouTube Reporting API(不是YouTube Analytics API),可在Google Cloud控制台的API库中搜索启用。
内容的提问来源于stack exchange,提问作者Dan Cooke
相关产品推荐
相关产品推荐

