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
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.
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"
}
}
]
}
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"
}
}
]
}
I have had the same problem and it is resolved by enabling the 'YouTube Data API v3' from the API Library
Related
Introducing handles: A new way to identify your YouTube channel
Does the YouTube Data API support querying for a channel by it's #handle? This does not seem to be supported.
ex: https://www.youtube.com/#lionsgatemovies
forUsername param
GET https://www.googleapis.com/youtube/v3/channels?part=id,snippet&forUsername=#lionsgatemovies
{
"kind": "youtube#channelListResponse",
"etag": "RuuXzTIr0OoDqI4S0RU6n4FqKEM",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 5
}
}
id param
GET https://www.googleapis.com/youtube/v3/channels?part=id,snippet&id=#lionsgatemovies
{
"kind": "youtube#channelListResponse",
"etag": "RuuXzTIr0OoDqI4S0RU6n4FqKEM",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 5
}
}
None of the supported filter params seem to be appropriate:
{
"error": {
"code": 400,
"message": "No filter selected. Expected one of: mySubscribers, forUsername, mine, managedByMe, categoryId, id",
"errors": [
{
"message": "No filter selected. Expected one of: mySubscribers, forUsername, mine, managedByMe, categoryId, id",
"domain": "youtube.parameter",
"reason": "missingRequiredParameter",
"location": "parameters.",
"locationType": "other"
}
]
}
}
You can use Search API with q parameter set to #handle
curl \
'https://youtube.googleapis.com/youtube/v3/search?part=snippet&maxResults=25&q=%40kevinrooke&type=channel&key=[YOUR_API_KEY]'
{
"kind": "youtube#searchListResponse",
"etag": "AYlro9VG2vMtdew4OQiWoQM8Rs0",
"regionCode": "LT",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "ls9E_ctoa-RLsqznJwxWlHHIE1s",
"id": {
"kind": "youtube#channel",
"channelId": "UCTdxV_ItCZMayyzGkw7P_qQ"
},
"snippet": {
"publishedAt": "2017-05-27T03:56:38Z",
"channelId": "UCTdxV_ItCZMayyzGkw7P_qQ",
"title": "Kevin Rooke",
"description": "Interviews with the builders bringing the Lightning Network to life. ⚡kerooke#fountain.fm.",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/ytc/AMLnZu-SpmaNjx7KOMqs5Cr7ZthU60BaQApzt89_dHOlcg=s88-c-k-c0xffffffff-no-rj-mo"
},
"medium": {
"url": "https://yt3.ggpht.com/ytc/AMLnZu-SpmaNjx7KOMqs5Cr7ZthU60BaQApzt89_dHOlcg=s240-c-k-c0xffffffff-no-rj-mo"
},
"high": {
"url": "https://yt3.ggpht.com/ytc/AMLnZu-SpmaNjx7KOMqs5Cr7ZthU60BaQApzt89_dHOlcg=s800-c-k-c0xffffffff-no-rj-mo"
}
},
"channelTitle": "Kevin Rooke",
"liveBroadcastContent": "none",
"publishTime": "2017-05-27T03:56:38Z"
}
}
]
}
As of this moment (17th Nov 2022), YouTube has yet to update the Data API with #handle support.
The channelId was scattered around in the Html. You can easily parse them after fetching the url with the handle.
const html = await(await fetch(url)).text()
const channelId = html.match(/(?<=channelId(":"|"\scontent="))[^"]+/g)[0];
Following is the python snippet while we are waiting for YouTube API's official support. This is inspired by goodhyun's wonderful thoughts.
import requests
import re
# return YouTube channel id via handle or False if failed
def scraping_get_channel_id_from_handle(handle:str):
if handle.find('#') == -1:
handle = '#' + handle
url = 'https://www.youtube.com/' + handle
resp = requests.get(url)
if resp.status_code == 200:
found = re.findall('"channelId":"([^"]*)","title"', resp.text)
return found[0]
else:
return False
We are trying to get data from the google search console API with dimension types - web, discover, googleNews, news, image, video. They are all listed in the google API documentation here
But we are getting a successful response from google API only for search types 'web', 'image', and 'news', please see it below
Request URL: https://www.googleapis.com/webmasters/v3/sites/sc-domain%3Amydomain.com/searchAnalytics/query?fields=responseAggregationType%2Crows
Request:
{
"startDate": "2022-06-05",
"endDate": "2022-06-22",
"dimensions": ["query","page","country"],
"type": "web",
"dataState": "all",
"aggregationType": "byPage",
"rowLimit": 5000,
"startRow": 0
}
Response:
Queries Count: 239752
========================================================================================
Request:
{
"startDate": "2022-06-05",
"endDate": "2022-06-22",
"dimensions": ["query","page","country"],
"type": "image",
"dataState": "all",
"aggregationType": "byPage",
"rowLimit": 5000,
"startRow": 0
}
Response:
Queries Count: 1827
====================================================================================
Request:
{
"startDate": "2022-06-05",
"endDate": "2022-06-22",
"dimensions": ["query","page","country"],
"type": "web",
"dimensionFilterGroups": [
{
"groupType": "and",
"filters": [
{
"dimension": "country",
"operator": "contains",
"expression": "GBR"
}
]
}
],
"dataState": "all",
"aggregationType": "byPage",
"rowLimit": 5000,
"startRow": 0
}
Response:
Queries Count: 9073
When we are making the same request with the search type 'discover' or 'googleNews' we are getting an error in the response as below
Request:
{
"startDate": "2022-06-05",
"endDate": "2022-06-22",
"dimensions": ["query","page","country"],
"type": "discover",
"dataState": "all",
"aggregationType": "byPage",
"rowLimit": 5000,
"startRow": 0
}
Response:
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"errors": [
{
"message": "Request contains an invalid argument.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}
We also have tried to make the API request for the full URL without sc-domain parameter as one below
https://www.googleapis.com/webmasters/v3/sites/https%3A%2F%2Fwww.mydomain.com/searchAnalytics/query?fields=responseAggregationType%2Crows
But still, we are getting the same errors.
My question is - what is wrong with our requests and how to get data from the google search console API for the search types 'discover' and 'googleNews'? And is there any way to get more informative error messages from google search console API responses, that will provide a bit more explanation about the reason for the error occurred?
For the channel.list function of the YouTube API are you able to call statistics for any channel on YouTube? Reviewing the below call parameters it seems all require you to be the owner of that channel to receive any information on that channel.
I've also tried the API test to see if I can receive data by username for the channel but doesn't seem to work. Beginner so if anyone could help out I'd much appreciate it!
https://developers.google.com/youtube/v3/docs/channels/list?apix_params=%7B%22forUsername%22%3A%22Peter%20McKinnon%22%7D
You do not need to be the owner of the channel you just need the channel Id. You can tests this using the try me on channel.list its a public api call.
request
GET https://www.googleapis.com/youtube/v3/channels?part=snippet%2CcontentDetails%2Cstatistics&id=UCeY0bbntWzzVIaj2z3QigXg&key=[YOUR_API_KEY] HTTP/1.1
Accept: application/json
response
{
"kind": "youtube#channelListResponse",
"etag": "y2BDT1Qkcr2Fm2FAHjDfG6Gn8Sc",
"pageInfo": {
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "VCwefXyl53bCqIREF0zJeTfxZXk",
"id": "UCeY0bbntWzzVIaj2z3QigXg",
"snippet": {
"title": "NBC News",
"description": "» Subscribe to NBC News:",
"customUrl": "nbcnews",
"publishedAt": "2006-07-19T20:46:03Z",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/a/AATXAJzjPejETKc2lrL43-9gFFWRL9WKwEmOIvtbWyait1c=s88-c-k-c0xffffffff-no-rj-mo",
"width": 88,
"height": 88
},
"medium": {
"url": "https://yt3.ggpht.com/a/AATXAJzjPejETKc2lrL43-9gFFWRL9WKwEmOIvtbWyait1c=s240-c-k-c0xffffffff-no-rj-mo",
"width": 240,
"height": 240
},
"high": {
"url": "https://yt3.ggpht.com/a/AATXAJzjPejETKc2lrL43-9gFFWRL9WKwEmOIvtbWyait1c=s800-c-k-c0xffffffff-no-rj-mo",
"width": 800,
"height": 800
}
},
"localized": {
"title": "NBC News",
"description": "» Subscribe to NBC News: "
}
},
"contentDetails": {
"relatedPlaylists": {
"likes": "",
"favorites": "",
"uploads": "UUeY0bbntWzzVIaj2z3QigXg",
"watchHistory": "HL",
"watchLater": "WL"
}
},
"statistics": {
"viewCount": "1942288925",
"commentCount": "0",
"subscriberCount": "3700000",
"hiddenSubscriberCount": false,
"videoCount": "25734"
}
}
]
}
I am using the Office365 API for calendar events. I am able to create an event successfully with Extensions (custom data) like below...
But, when I get calendar events it does not return back any Extensions data field.
GET https://outlook.office.com/api/v2.0/me/events
How do I get the Extensions back in the events data?
POST: https://outlook.office.com/api/v2.0/me/events
authorization: bearer {token}
content-type: application/json
{
"Subject": "Discuss the Calendar REST API",
"Body": {
"ContentType": "HTML",
"Content": "I think it will meet our requirements!"
},
"Start": {
"DateTime": "2016-09-06T18:00:00",
"TimeZone": "Pacific Standard Time"
},
"End": {
"DateTime": "2016-09-06T18:00:00",
"TimeZone": "Pacific Standard Time"
},
"Extensions": [
{
"#odata.type": "Microsoft.OutlookServices.OpenTypeExtension",
"ExtensionName": "Com.Contoso.Referral",
"CompanyName": "Wingtip Toys",
"ExpirationDate": "2015-12-30T11:00:00.000Z",
"DealValue": 10000,
"TopModels": [
3001,
4002,
5003
],
"TopSalespersons": [
"Dana Swope",
"Fanny Downs",
"Randi Welch"
]
}]
}
You could get extension using the below api:
GET https://outlook.office.com/api/v2.0/me/events('{event_id}')/extensions('{extensionId}')
For example:
GET https://outlook.office.com/api/v2.0/me/messages('AAMkAGE1M2IyNGNmLTI5MTktNDUyZi1iOTVl===')/extensions('Com.Contoso.Referral')
For more information, please refer to the below link:
Get extension
I am not getting "nextPageToken" in the response object when I tried to retrieve list of users who subscribed to our channels using YT Data API (v3) Subscription. For some reason YT not returning "nextPageToken" even though below channel has more than 100K subscribers so could you please advise me on how to be able to fetch next pages of subscribers. Same behavior happening when I tried with any of channels from our CMS account:
Request:
https://www.googleapis.com/youtube/v3/subscriptions?onBehalfOfContentOwner=xxxx&onBehalfOfContentOwnerChannel=xxxxxxxxxxx&fields=items(contentDetails,id,snippet(publishedAt,channelId),subscriberSnippet(title,description)),nextPageToken,pageInfo,tokenPagination&maxResults=50&mySubscribers=true&part=id,snippet,contentDetails,subscriberSnippet&key=xxxxxxxxxxxxxxxx
Here is sample response snippet (I trimmed out other 48 items from below list and intentionally masked out subscriber details)
{
"items": [
{
"snippet": {
"channelId": "UCUR8UieACc2QXl7waH821hQ",
"publishedAt": "2014-05-20T19:50:44.000Z"
},
"contentDetails": {
"newItemCount": 0,
"activityType": "all",
"totalItemCount": 51
},
"subscriberSnippet": {
"description": "",
"title": "Sebastian Brentsworth"
},
"id": "MVPSEm5kMooIHMvcBKqbtFJAp1dHw0GeHza2Iq5KXP"
},
{
"snippet": {
"channelId": "UCYs04YSyy1soNzyvsDljYVg",
"publishedAt": "2014-05-28T22:39:30.000Z"
},
"contentDetails": {
"newItemCount": 0,
"activityType": "all",
"totalItemCount": 51
},
"subscriberSnippet": {
"description": "",
"title": "Jason Chan"
},
"id": "Xd7_fS3FIA4rnSu6NXEfxF8trXzL8-LspvIuYtDMmc0"
}
],
"pageInfo": {
"resultsPerPage": 50,
"totalResults": 144403
}
}
"Known" (Hopefully also to Google) bug:
https://code.google.com/p/gdata-issues/issues/detail?id=7163 and youtube.subscriptions.list (api v3) - nextPageToken isn't available
For the time being, I've came up with a token generator as a workaround (see other SO post, or here: https://gist.github.com/pulsar256/f5621e85ef50711adc6f)