我正在尝试拨打此电话给Youtube 频道 API,但回复没有contentOwnerDetails。问题是什么?为什么Youtube“频道”API不返回“contentOwnerDetails”数据?
GET https://www.googleapis.com/youtube/v3/channels?part=id%2CcontentDetails%2CcontentOwnerDetails&mine=true&key={YOUR_API_KEY}
我正在尝试拨打此电话给Youtube 频道 API,但回复没有contentOwnerDetails。问题是什么?为什么Youtube“频道”API不返回“contentOwnerDetails”数据?
GET https://www.googleapis.com/youtube/v3/channels?part=id%2CcontentDetails%2CcontentOwnerDetails&mine=true&key={YOUR_API_KEY}
为了您GET方法URI
https://www.googleapis.com/youtube/v3/channels?part=id%2CcontentDetails%2CcontentOwnerDetails&mine=true&key={YOUR_API_KEY}
的JSON回应如下
{
"error": {
"errors": [
{
"domain": "youtube.parameter",
"reason": "authorizationRequired",
"message": "The request uses the <code>mine</code> parameter but is not properly authorized.",
"locationType": "parameter",
"location": "mine"
}
],
"code": 401,
"message": "The request uses the <code>mine</code> parameter but is not properly authorized."
}
}
根据YouTube数据API - 错误
401(未经授权) - authorizationRequired - 请求使用矿山 参数,但没有正确授权。
矿参数值必须设置为true,指示API只返回被认证的用户所拥有的渠道。 (布尔)
推论:您没有授权从内容所有者,即YouTube频道所有者可能访问该频道的内容不准到您的应用程序的内容。
这是一个权限问题。 URI中的channelId在哪里?可能应该添加它。
如果您没有自己的渠道API不会返回contentOwnerDetails。由于您使用的是mine=true
参数,因此您需要在API返回contentOwnerDetails之前先通过OAuth正确授权。请参阅https://developers.google.com/youtube/v3/guides/authentication
如果我正确地忽略了“频道”API,它将返回授权用户拥有的频道列表(在“项目”属性中)。那么我怎么能看到他的Google user_id? – micobg
不,这不是权限问题。我被授权,这不是问题。我使用此页面(https://developers.google.com/youtube/v3/docs/channels/list#try-it)发出请求并给出了权限。请求是正确的,没有错误,所以没有认证的问题。我的问题是为什么contentOwnerDetails在响应中缺失?它包含在“零件”列表中。我需要contentOwnerDetails.contentOwner来获取用户的ID。 – micobg