Reputation: 61
I am getting a 403 forbidden error when making an API call to the YouTube Data API.
I have tried to generate different types of keys (Web Browser, Server, etc.). The key is unrestricted. I have tried making the call from a server and from postman for Chrome. The request URL and response is below.
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"
}
}
Here are the headers:
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
Upvotes: 6
Views: 18890
Reputation: 4736
In my case, my Gmail account has a specific YouTube sub-account, so when giving consent in the Browser, make sure you pick your correct YouTube sub-account.
Also, make sure you tick the box, in the last step of consent - it's not ticked by default.
Upvotes: 0
Reputation: 663
I have had the same problem and it is resolved by enabling the 'YouTube Data API v3' from the API Library
Upvotes: 0
Reputation: 1379
These types of error related to YouTube APIs core apis errors
Core API errors
forbidden (403) : Access forbidden :The request may not be properly authorized.
quotaExceeded (403) : quotaExceeded : The request cannot be completed because you have exceeded your quota.
You can try adding OAuth using this documentation on YouTube Data API Overview as a guide.
If your application will use any API methods that require user authorization, read the authentication guide to learn how to implement OAuth 2.0 authorization.
If you are getting the same error then , verify the YouTube Data API v3 service enabled for this key in your Google Developers console.
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"
}
}
]
}
Upvotes: 1
Reputation: 265
I tested this with multiple api-keys and I didn't hit an issue.
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"
}
}
]
}
Upvotes: 0
Reputation: 6729
This error is a Core API error as what specified in the Youtube API documentation.
Access forbidden. The request may not be properly authorized.
You can check the step by step guide provided in the documentation. You will bump with the step on how to properly acquire user authorization.
Intended for developers who want to write applications that interact with YouTube. It explains basic concepts of YouTube and of the API itself. It also provides an overview of the different functions that the API supports.
Upvotes: 0