I am calling youtube api for videos.list(https://developers.google.com/youtube/v3/docs/videos/list) with part="snippet,contentDetails,status,statistics,topicDetails". On Apr 6 or 7 2017 something changed and for many videos I don't get field "statistics". I'm wondering, why this happens and how I can get publicly available counts, like viewCount, for them?
Here are a couple of example videos: PiZEMoZ535I,vHw_drm5cRk
This is likely a bug, it was working fine until April 7th. There's an Issue Tracker created for that, however Google still didn't say anything about this.
EDIT:
This seems to finally be fixed
You need to make a call to the API with the resource video.list with parameters :
part: statistics
id: "id of the video found in previous request"
If you have more than one video id you can specify the id of videos with a comma-separated list like :
id: "Xxsdw6zG1bg, Xxsdw6zG1bg,...." )
The request: https://www.googleapis.com/youtube/v3/videospart=statistics&id=UHdgXkkVyl0%2C+Xxsdw6zG1bg&key={YOUR_API_KEY}
The response will be like this :
{
"kind": "youtube#videoListResponse",
"etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/rxvjZzq2nNqBg7Me5VQv1ToZm64\"",
"pageInfo": {
"totalResults": 2,
"resultsPerPage": 2
},
"items": [
{
"kind": "youtube#video",
"etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/3fah-cngFxFOnytseMYZU1TK_-8\"",
"id": "UHdgXkkVyl0",
"statistics": {
"viewCount": "3070836",
"likeCount": "72140",
"dislikeCount": "1132",
"favoriteCount": "0",
"commentCount": "7798"
}
},
{
"kind": "youtube#video",
"etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/J4xM7Dd23TGYU6on-PESyEIAE9A\"",
"id": "Xxsdw6zG1bg",
"statistics": {
"viewCount": "131487",
"likeCount": "1459",
"dislikeCount": "25",
"favoriteCount": "0",
"commentCount": "39"
}
}
]
}
And you have the statistics !
Related
I am currently using the Youtube data API trying to get localised subtitle data and while this works for most videos it isn't working for this one: https://www.youtube.com/watch?v=Q0FhXknxYj4. The video has Danish subtitles but when you use the API or API demo (setting part as localization) here: https://developers.google.com/youtube/v3/docs/videos/list there is no subtitle data.
Example response for working video:
{
"kind": "youtube#videoListResponse",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/zgsYC3imu6Fd_dFVfGFSGv4yads\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/3xUeT9GTC6osUJsmbTXqY1OMfsc\"",
"id": "S3YnYrcD1sQ",
"localizations": {
"da": {
"title": "København: Europas første markedsplads for byrelaterede data - Hitachi",
"description": "Hitachi skaber en datamarkedsplads for Danmarks hovedstad, der skal styrke innovationen.\n\nhttp://www.hitachi.eu/en/case_studies/city-data-exchange"
},
"en": {
"title": "Copenhagen: Europe's first city data exchange - Hitachi",
"description": "Hitachi is creating a data marketplace for Denmark's capital, to help power innovation.\n\nhttp://www.hitachi.eu/en/case_studies/city-data-exchange"
}
}
}
]
}
Example response for broken video (Q0FhXknxYj4):
{
"kind": "youtube#videoListResponse",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/UrnoPP0xkF1sGZFODge_h_h01KU\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/Y82zqHiktkqS1qFvTSCoJ5BEJas\"",
"id": "Q0FhXknxYj4"
}
]
}
Does anyone know why the API might not pull in the localisation data even though the subtitles are there?
Many thanks,
Emily
Your first example does not contain any subtitle data either. It only contains localizations of the video title and description.
You need to be using captions, not list, to list subtitle details.
After deleating comment on video commentCount field is not updated. For example, this video was with 1 comment but after I deleted it the API continues to return 1 as count of comments.
Api call:
https://www.googleapis.com/youtube/v3/videos
part: id,statistics
id: CoDoe6rK2a0
Response:
{
"kind": "youtube#videoListResponse",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/j7tFb2p4vQHvGO4jdm1Qvuz01zo\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/SP5Xvf63pkDP90houUhxO95qiKM\"",
"id": "CoDoe6rK2a0",
"statistics": {
"viewCount": "14",
"likeCount": "0",
"dislikeCount": "0",
"favoriteCount": "0",
"commentCount": "1"
}
}
]
}
But as you can see in Youtube the list of comments is empty and the response of v3/comments endpoint is empty items array also.
Using Videos.list Try-it works as expected and updates fast.
part: statistics
videoId: MY_VIDEO_ID
When I deleted one of the comments and ran the Try-it, it updated immediately.
Make sure you're internet connection is working fine too.
I have noticed that all videos from the account, Kanye West - Topic, don't show up in the api results. Does anyone have a reason why or a solution to fix this? For example, when I use the api search GET https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCRY5dYsbIN5TylSbd7gVnZg&type=video&key={YOUR_API_KEY}, it says there are 961 total results but the items section is empty.
Your GET request is correct but it's missing additional field resources parameters, so it doesn't know what you want to retrieve. I've added the fields to your GET REQUEST using the Google API Explorer and here's what it looks like:
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCRY5dYsbIN5TylSbd7gVnZg&maxResults=50&q=%22Kanye+West%22&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CprevPageToken%2CregionCode%2CtokenPagination%2CvisitorId&key={API_KEY_HERE}
And the response was:
{
"kind": "youtube#searchListResponse",
"etag": "\"GM4ZnRh2gk1X1BLWgHklTm-3cgQ/6VdmXA4FhXjg08y58iRnmXZY7wQ\"",
"nextPageToken": "CDIQAA",
"regionCode": "PH",
"pageInfo": {
"totalResults": 841,
"resultsPerPage": 50
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"GM4ZnRh2gk1X1BLWgHklTm-3cgQ/VSzDMW_CqJw-OMjo_vzPR2P40eI\"",
"id": {
"kind": "youtube#channel",
"channelId": "UCRY5dYsbIN5TylSbd7gVnZg"
},
"snippet": {
"publishedAt": "2013-07-02T20:09:18.000Z",
"channelId": "UCRY5dYsbIN5TylSbd7gVnZg",
"title": "Kanye West - Topic",
"description": "Kanye Omari West is an American rapper, songwriter, record producer, fashion designer, and entrepreneur. Born in Atlanta and raised in Chicago, West first ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/i/RY5dYsbIN5TylSbd7gVnZg/1.jpg"
},
"medium": {
"url": "https://i.ytimg.com/i/RY5dYsbIN5TylSbd7gVnZg/mq1.jpg"
},
"high": {
"url": "https://i.ytimg.com/i/RY5dYsbIN5TylSbd7gVnZg/hq1.jpg"
}
},
"channelTitle": "Kanye West - Topic",
"liveBroadcastContent": "none"
}
.. (long list below)
If you want to conduct additonal test, use the Youtube API Explorer.
Using the Youtube Data API's Channels:list with the brandingSettings part works when using the id filter but not the forUsername filter for me.
For example, GET https://www.googleapis.com/youtube/v3/channels?part=brandingSettings&forUsername=h3h3Productions&key={YOUR_API_KEY} results in the following, which is missing brandSettings:
{
"kind": "youtube#channelListResponse",
"etag": "\"0KG1mRN7bm3nResDPKHQZpg5-do/Qagk6ayL_umilQ398UZyAHwxK_g\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"0KG1mRN7bm3nResDPKHQZpg5-do/tTzKQvYs0Y2GpqN2wqgudxB2TnQ\"",
"id": "UCDWIvJwLJsE4LG1Atne2blQ"
}
]
}
But GET https://www.googleapis.com/youtube/v3/channels?part=brandingSettings&id=UCDWIvJwLJsE4LG1Atne2blQ&key={YOUR_API_KEY} (which you'll notice uses the ID of the same user), leaves it intact:
{
"kind": "youtube#channelListResponse",
"etag": "\"0KG1mRN7bm3nResDPKHQZpg5-do/2ZOHdezDOZFRR9xisREY04R4OOg\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"0KG1mRN7bm3nResDPKHQZpg5-do/58_5G5_Hi-64MiC8m5NC76sDIOA\"",
"id": "UCDWIvJwLJsE4LG1Atne2blQ",
"brandingSettings": {
"channel": {
"title": "h3h3Productions",
"description": "Wacky, zany, goofy comedy. ",
"keywords": "comedy humor satire parody funny sketch \"sketch comedy\" reaction \"reaction video\" review h3h3 h3h3productions",
"showRelatedChannels": true,
"showBrowseView": true,
"featuredChannelsTitle": "SECOND CHANNEL",
"featuredChannelsUrls": [
"UC7pp40MU_6rLK5pvJYG3d0Q"
],
"unsubscribedTrailer": "tVaAv0cPRok",
"profileColor": "#000000",
"country": "US"
},
"image": {
"bannerImageUrl": "https://yt3.ggpht.com/-DFbgqVWqgm8/VDV_M-xkJtI/AAAAAAAAAOE/zQeoRrTR-qA/w1060-fcrop64=1,00005a57ffffa5a8-nd/youtube%2Bnew%2Bbanner14.jpg",
"bannerMobileImageUrl": "https://yt3.ggpht.com/-DFbgqVWqgm8/VDV_M-xkJtI/AAAAAAAAAOE/zQeoRrTR-qA/w640-fcrop64=1,32b75a57cd48a5a8-nd/youtube%2Bnew%2Bbanner14.jpg",
"bannerTabletLowImageUrl": "https://yt3.ggpht.com/-DFbgqVWqgm8/VDV_M-xkJtI/AAAAAAAAAOE/zQeoRrTR-qA/w1138-fcrop64=1,00005a57ffffa5a8-nd/youtube%2Bnew%2Bbanner14.jpg",
"bannerTabletImageUrl": "https://yt3.ggpht.com/-DFbgqVWqgm8/VDV_M-xkJtI/AAAAAAAAAOE/zQeoRrTR-qA/w1707-fcrop64=1,00005a57ffffa5a8-nd/youtube%2Bnew%2Bbanner14.jpg",
"bannerTabletHdImageUrl": "https://yt3.ggpht.com/-DFbgqVWqgm8/VDV_M-xkJtI/AAAAAAAAAOE/zQeoRrTR-qA/w2276-fcrop64=1,00005a57ffffa5a8-nd/youtube%2Bnew%2Bbanner14.jpg",
"bannerTabletExtraHdImageUrl": "https://yt3.ggpht.com/-DFbgqVWqgm8/VDV_M-xkJtI/AAAAAAAAAOE/zQeoRrTR-qA/w2560-fcrop64=1,00005a57ffffa5a8-nd/youtube%2Bnew%2Bbanner14.jpg",
"bannerMobileLowImageUrl": "https://yt3.ggpht.com/-DFbgqVWqgm8/VDV_M-xkJtI/AAAAAAAAAOE/zQeoRrTR-qA/w320-fcrop64=1,32b75a57cd48a5a8-nd/youtube%2Bnew%2Bbanner14.jpg",
"bannerMobileMediumHdImageUrl": "https://yt3.ggpht.com/-DFbgqVWqgm8/VDV_M-xkJtI/AAAAAAAAAOE/zQeoRrTR-qA/w960-fcrop64=1,32b75a57cd48a5a8-nd/youtube%2Bnew%2Bbanner14.jpg",
"bannerMobileHdImageUrl": "https://yt3.ggpht.com/-DFbgqVWqgm8/VDV_M-xkJtI/AAAAAAAAAOE/zQeoRrTR-qA/w1280-fcrop64=1,32b75a57cd48a5a8-nd/youtube%2Bnew%2Bbanner14.jpg",
"bannerMobileExtraHdImageUrl": "https://yt3.ggpht.com/-DFbgqVWqgm8/VDV_M-xkJtI/AAAAAAAAAOE/zQeoRrTR-qA/w1440-fcrop64=1,32b75a57cd48a5a8-nd/youtube%2Bnew%2Bbanner14.jpg",
"bannerTvImageUrl": "https://yt3.ggpht.com/-DFbgqVWqgm8/VDV_M-xkJtI/AAAAAAAAAOE/zQeoRrTR-qA/w2120-fcrop64=1,00000000ffffffff-nd/youtube%2Bnew%2Bbanner14.jpg",
"bannerTvLowImageUrl": "https://yt3.ggpht.com/-DFbgqVWqgm8/VDV_M-xkJtI/AAAAAAAAAOE/zQeoRrTR-qA/w854-fcrop64=1,00000000ffffffff-nd/youtube%2Bnew%2Bbanner14.jpg",
"bannerTvMediumImageUrl": "https://yt3.ggpht.com/-DFbgqVWqgm8/VDV_M-xkJtI/AAAAAAAAAOE/zQeoRrTR-qA/w1280-fcrop64=1,00000000ffffffff-nd/youtube%2Bnew%2Bbanner14.jpg",
"bannerTvHighImageUrl": "https://yt3.ggpht.com/-DFbgqVWqgm8/VDV_M-xkJtI/AAAAAAAAAOE/zQeoRrTR-qA/w1920-fcrop64=1,00000000ffffffff-nd/youtube%2Bnew%2Bbanner14.jpg"
},
"hints": [
{
"property": "channel.banner.mobile.medium.image.url",
"value": "https://yt3.ggpht.com/-DFbgqVWqgm8/VDV_M-xkJtI/AAAAAAAAAOE/zQeoRrTR-qA/w640-fcrop64=1,32b75a57cd48a5a8-nd/youtube%2Bnew%2Bbanner14.jpg"
},
{
"property": "channel.banner.image_height.int",
"value": "0"
},
{
"property": "channel.featured_tab.template.string",
"value": "Everything"
},
{
"property": "channel.modules.show_comments.bool",
"value": "True"
}
]
}
}
]
}
Am I doing something wrong? Keeping everything the same but switching the part to snippet or statistics works how you'd expect in both cases. I've also tried this on a few more channels and get the same results.
I think this is working as intended. See YouTube API - No channel branding settings returned for queries by username. Tl;dr: even though you can look for channels by using their usernames, the migration from V2 carried with it the fact that not every YouTube channel has a unique username, so that's why it works correctly when you use the channel ID (which is unique). I also tried it by specifying forMine instead of the channel ID and it worked as expected.
I'm searching youtube videos with youtube api 3.0.
I'm using this type of example API request
https://www.googleapis.com/youtube/v3/search?part=snippet&key=[API_KEY]
But i want to get statistics of videos with in the same api request. How to solve this problem.
Note: When I'm using statistics key with part. I got error.
I'm also tried this request
https://www.googleapis.com/youtube/v3/search?part=snippet,statistics&key=[API_KEY]
The resource search.list don't have the part statistics.
Step 1 :
You need to get the videoId of the video: "videoId": "UHdgXkkVyl0" with search.list.
The request :
https://www.googleapis.com/youtube/v3/search?part=id&q=tuto&type=video&key={YOUR_API_KEY}
The response:
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/34CzOO9FXYQg7kdlOeoe59LsWVk\"",
"id": {
"kind": "youtube#video",
"videoId": "UHdgXkkVyl0"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/U303dB0TgZ89ODlqdwuKs5efOdk\"",
"id": {
"kind": "youtube#video",
"videoId": "LvEA2KHWQec"
}
},
Step 2 :
After you have searched videos with search.list you need to make a second call to the API with the resource video.list with parameters :
part: statistics
id: "id of the video found in previous request"
If you have more than one video id you can specify the id of videos with a comma-separated list like :
id: "Xxsdw6zG1bg, Xxsdw6zG1bg,...." )
The request: https://www.googleapis.com/youtube/v3/videos?part=statistics&id=UHdgXkkVyl0%2C+Xxsdw6zG1bg&key={YOUR_API_KEY}
The response will be like this :
{
"kind": "youtube#videoListResponse",
"etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/rxvjZzq2nNqBg7Me5VQv1ToZm64\"",
"pageInfo": {
"totalResults": 2,
"resultsPerPage": 2
},
"items": [
{
"kind": "youtube#video",
"etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/3fah-cngFxFOnytseMYZU1TK_-8\"",
"id": "UHdgXkkVyl0",
"statistics": {
"viewCount": "3070836",
"likeCount": "72140",
"dislikeCount": "1132",
"favoriteCount": "0",
"commentCount": "7798"
}
},
{
"kind": "youtube#video",
"etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/J4xM7Dd23TGYU6on-PESyEIAE9A\"",
"id": "Xxsdw6zG1bg",
"statistics": {
"viewCount": "131487",
"likeCount": "1459",
"dislikeCount": "25",
"favoriteCount": "0",
"commentCount": "39"
}
}
]
}
And you have the statistics !
Unfortunately, dislikeCount attribute has became private, in december 2021. according the youtube api docs.