对YouTube数据API进行API调用时,我收到403禁止错误。
我尝试生成不同类型的密钥(Web浏览器,服务器等)。密钥不受限制。我尝试从服务器和Chrome的邮递员拨打电话。请求网址和响应如下。
https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=1&q=surfing&key={api-key}
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Forbidden"
}
],
"code": 403,
"message": "Forbidden"
}
}
以下是标题:
alt-svc →quic=":443"; ma=2592000; v="43,42,41,39,35"
cache-control →private, max-age=0
content-encoding →gzip
content-length →118
content-type →application/json; charset=UTF-8
date →Tue, 10 Jul 2018 15:00:27 GMT
expires →Tue, 10 Jul 2018 15:00:27 GMT
server →GSE
status →403
vary →Origin, X-Origin
x-content-type-options →nosniff
x-frame-options →SAMEORIGIN
x-xss-protection →1; mode=block
答案 0 :(得分:3)
此错误是Core API error,与Youtube API文档中指定的错误相同。
禁止访问。该请求可能未得到适当的授权。
您可以查看documentation中提供的逐步指南。您将逐步了解如何正确获取用户authorization的步骤。
适用于希望编写交互应用程序的开发人员 YouTube。它说明了YouTube和API的基本概念 本身。它还概述了不同的功能 API支持。
答案 1 :(得分:0)
我用多个api键对此进行了测试,但没有遇到任何问题。
curl https://www.googleapis.com/youtube/v3/search\?part\=snippet\&maxResults\=1\&q\=surfing\&key\={api-key}
{
"kind": "youtube#searchListResponse",
"etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/r9B676JRBM0twgG6dy2MZT_1KnQ\"",
"nextPageToken": "CAEQAA",
"regionCode": "US",
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/E8GZG_CZfJeaVF75eZYmJHnGe0c\"",
"id": {
"kind": "youtube#video",
"videoId": "rj7xMBxd5iY"
},
"snippet": {
"publishedAt": "2017-11-12T11:09:52.000Z",
"channelId": "UCiiFGfvlKvX3uzMovO3unaw",
"title": "BIG WAVE SURFING COMPILATION 2017",
"description": "BIG WAVE SURFING COMPILATION 2017 ** REVISED **AMAZING FOOTAGE ** WITH 60-100FT- HUGE SURF Please Subscribe if You Would like to see More ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/rj7xMBxd5iY/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/rj7xMBxd5iY/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/rj7xMBxd5iY/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Absolutely Flawless",
"liveBroadcastContent": "none"
}
}
]
}
答案 2 :(得分:0)
这些与YouTube API核心api错误有关的错误类型
核心API错误
禁止访问(403):禁止访问:请求可能不正确 授权。
quotaExceeded(403):quotaExceeded:请求不能 已完成,因为您已超出配额。
您可以尝试使用YouTube数据API概述上的此文档作为指南来添加OAuth。
如果您的应用程序将使用需要用户的任何API方法 授权,请阅读身份验证指南以了解如何实施 OAuth 2.0授权。
如果遇到相同的错误,请在Google Developers console中验证为此密钥启用的YouTube Data API v3服务。
URL : https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=1&q=surfing&key={API_KEY}
{
"kind": "youtube#searchListResponse",
"etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/vxoFCv0dm4WdeKtXnUk7GXCJeao\"",
"nextPageToken": "CAEQAA",
"regionCode": "IN",
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/Amykv1hEk5vzuqlcAS8z2BEptrU\"",
"id": {
"kind": "youtube#video",
"videoId": "CWYDxh7QD34"
},
"snippet": {
"publishedAt": "2014-09-02T16:52:33.000Z",
"channelId": "UCblfuW_4rakIf2h6aqANefA",
"title": "Best surfing action from Red Bull Cape Fear 2014",
"description": "Click for the FULL EVENT: http://www.redbullcapefear.com/ The southern tip of Sydney Australia is home to one of the most treacherous waves on the planet: ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/CWYDxh7QD34/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/CWYDxh7QD34/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/CWYDxh7QD34/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Red Bull",
"liveBroadcastContent": "none"
}
}
]
}
答案 3 :(得分:0)
我遇到了同样的问题,可以通过从API库启用“ YouTube数据API v3”来解决