Youtube Playlists API pageInfo.totalResults and items are inconsistent - youtube-api

The Youtube Playlists API playlistResponse.pageInfo.totalResults and playlistResponse.items are inconsistent.
pageInfo.totalResults includes the “Liked videos” playlist, however, items does not include this playlist.
This issue is easier to observe if the number of playlists in the account is less than maxResults.
Call the list method with the following request parameters:
maxResults: 50
mine: true
Actual result: totalResults includes the "Liked Videos" playlist. For example, if the user has 7 playlists, totalResults is 8 as it includes “Liked videos”
Expected result: Either totalResults does not include the “Liked videos” playlist, or items does.
For example, I have 7 playlists, 8 including "Liked Videos". Here totalResults includes the "Liked Vidoes" playlist, whereas items does not.
{
"kind": "youtube#playlistListResponse",
"etag": "MRBqnBy-Y8RQ0TpqYmpqAE_05Lw",
"nextPageToken": "CAUQAA",
"pageInfo": {
"totalResults": 8,
"resultsPerPage": 7
},
"items": [
{
"kind": "youtube#playlist",
"etag": "5-eWNGtmTPD4efCrIJvSCJwbYfE",
"id": "ozfDHFjXSdWdBqXDbH0W"
},
{
"kind": "youtube#playlist",
"etag": "vAMuqE_49abzgSQTTSroegIi2xU",
"id": "tglNJQrU86MyB7b3iqH5"
},
{
"kind": "youtube#playlist",
"etag": "D5Yv5VC-ZJ5wrJ6BV6Wbv0cSVXw",
"id": "6zz7DncBpOw8Uzx0hYeV"
},
{
"kind": "youtube#playlist",
"etag": "OyI6XYGqAITCIBIgNZhKZh9akXs",
"id": "Zbz6LcJlQYc2l3Wt73kr"
},
{
"kind": "youtube#playlist",
"etag": "Mexdqkd9YgKdOcMtRM8joax6Jfs",
"id": "UjcPmVI0zukbmnvWXiEi"
},
{
"kind": "youtube#playlist",
"etag": "Mexdqkd9YgKdOcMtRM8joax6Jfs",
"id": "p6ocnzio8hKNKAe85m6m"
},
{
"kind": "youtube#playlist",
"etag": "Mexdqkd9YgKdOcMtRM8joax6Jfs",
"id": "OXCW0pdVWeYLjPsXN1mA"
}
]
}

Related

YouTube API 3 channels by username and id inconsistant

Why is it when I search for a channel by ID https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=UU-tdS40X5ld-a4KfarLJuDw&key=[YOUR_API_KEY] I get no items returned.
But when I search by userName, it returns the channel ID that I just searched for https://www.googleapis.com/youtube/v3/channels?part=contentDetails&forUsername=washingtonstateuniv&key=[YOUR_API_KEY]
when I search for a channel by ID .. I get no items returned.
Give the Try-it section for channels.list a try. I'm able to fetch JSON response by using these parameters:
part->contentDetails
id-> yourchannel ID
Authorize and Execute
The response it returned is not empty at all.
{
"kind": "youtube#channelListResponse",
"etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/FiuYcDu7WFmoFVcLDRvENYGl_tQ\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/QjMybH99xT3x-znrh2Yerx_0DWk\"",
"id": "{my channel id}",
"snippet": {
"title": "{my channel name}",
"description": "",
"publishedAt": "2011-10-10T15:30:40.000Z",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/-EN5H1HDHqIU/ABCDEFGHIJK/ABCDEFGHIJK/l2gqeYg94P8/s88-c-k-no-mo-rj-c0xffffff/photo.jpg"
},
"medium": {
"url": "https://yt3.ggpht.com/-EN5H1HDHqIU/ABCDEFGHIJK/ABCDEFGHIJK/l2gqeYg94P8/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
},
"high": {
"url": "https://yt3.ggpht.com/-EN5H1HDHqIU/ABCDEFGHIJK/ABCDEFGHIJK/l2gqeYg94P8/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
}
},
"localized": {
"title": "{my channel name}",
"description": ""
}
}
}
]
}
That's a lot of results for me.
But when I search by userName, it returns the channel ID that I just
searched for.
In the channels.list try-it docs above, forUsername is defined as the forUsername parameter specifies a YouTube username, thereby requesting the channel associated with that username. So I think it's doing it's job.
Additional note on forUsername parameter is that's it's used to translate your arbitrary legacy YouTube username, that's the old Youtube accounts, into a channel ID using v3 of the API. More of that in Work with Channel IDs guide.
when I search by userName, it returns the channel ID that I just
searched for
You miss the important part to search by forUsername or channelID. That is snippet part, not contentDetails.
by forUsername :
https://www.googleapis.com/youtube/v3/channels?&part=snippet,id&forUsername=RealMiBs&title&key={YOUR_API_KEY}
by id channel:
https://www.googleapis.com/youtube/v3/channels?&part=snippet,id&id=UC_pwIXKXNm5KGhdEVzmY60A&title&key={YOUR_API_KEY}
That will exactly returned to like below:
{
"kind": "youtube#channelListResponse",
"etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/VnicD0AYsCI7KlKKcdsmdIlWUMs\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/Nl4tuuOFwuPOdHmP_Ky3vuIQ2Gg\"",
"id": "UC_pwIXKXNm5KGhdEVzmY60A",
"snippet": {
"title": "CJENMMUSIC Official", <== Channel Name
"description": "Asia's No.1 Entertainment & Media Company", <== Channel Desctiption
"customUrl": "cjenmmusic", <=== Channel URL who has been qualified - to and for - claimed it
"publishedAt": "2011-03-25T04:48:40.000Z",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/-QMkGdFbhrOc/AAAAAAAAAAI/AAAAAAAAAAA/6boUKax-3EA/s88-c-k-no-mo-rj-c0xffffff/photo.jpg"
},
"medium": {
"url": "https://yt3.ggpht.com/-QMkGdFbhrOc/AAAAAAAAAAI/AAAAAAAAAAA/6boUKax-3EA/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
},
"high": {
"url": "https://yt3.ggpht.com/-QMkGdFbhrOc/AAAAAAAAAAI/AAAAAAAAAAA/6boUKax-3EA/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
}
},
"localized": {
"title": "CJENMMUSIC Official",
"description": "Asia's No.1 Entertainment & Media Company"
}
}
}
]
}
While if you just pointing to contentDetails, it will return to almost nothing:
{
"kind": "youtube#channelListResponse",
"etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/C7SnOhT2c-Fs2R9f6JlxlOPWc34\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/3RTKaEQC9GX8c58R2Bhd8G1y3zM\"",
"id": "UC_pwIXKXNm5KGhdEVzmY60A",
"contentDetails": { <============== detail contents
"relatedPlaylists": {
"uploads": "UU_pwIXKXNm5KGhdEVzmY60A",
"watchHistory": "HL",
"watchLater": "WL"
}
}
}
]
}

How can I tell if a Youtube video cannot be viewed with Restricted Mode enabled?

Using the youtube Data API - videos: For a few videos using contentDetails.contentRating.ytRating shows that the video is ytAgeRestricted.
However most videos blocked in restricted mode do not have a contentRating in the JSON. E.g.:
https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=vBkBS4O3yvY&key={API_KEY}
Only the following is returned:
{
"kind": "youtube#videoListResponse",
"etag": "\"abQHWywil_AkNqdqji7_FqiK-u4/MGunVBb8A5UKg1uOrK7QknvhVZ8\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"abQHWywil_AkNqdqji7_FqiK-u4/n1iZ1JVdolHHrm8Nd2wvTRcfe5s\"",
"id": "vBkBS4O3yvY",
"contentDetails": {
"duration": "PT5M41S",
"dimension": "2d",
"definition": "hd",
"caption": "false",
"licensedContent": true
}
}
]
}

Youtube API 3.0 search videos and get video statistics at single request

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.

Get latest uploads using the v3 version of YouTube gData

Does anyone know how to get the latest uploads for a specific channel (or user will do too)?
In v2 of the gdata api you had the 'http://gdata.youtube.com/feeds/users/[username]/uploads?alt=json' call. But that's deprecated. In v3 there's the youtube.activities.list function, but that doesn't give the same results.
I thought I could get the playlists first, but than I seem to be missing some uploads that are not in a playlist.
Any suggestions?
To get the lastest uploads of a specific channel, don't pass by : youtube.activities.list.
The YouTube API V3 provide a special playlist of the uploads.
To get the id of the playlist two important link :
https://developers.google.com/youtube/v3/docs/channels/list?hl=fr
https://developers.google.com/youtube/v3/docs/playlistItems/list?hl=fr
And the two steps to get the uploads :
You need to use youtube.channel.list with the parameters :
part=contentDetails
id=ID_OF_THE_CHANNEL
The result is like this :
{
"kind": "youtube#channelListResponse",
"etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/CMNDR4CfkeuPx4qnAlqzH11BB5A\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/MeyW1Z8CbXCFwqPMlOLEwNZyMc0\"",
"id": "UCzOpxz1sdfp_0eRYqXkoSNA",
"contentDetails": {
"relatedPlaylists": {
"likes": "qsdqsxz1y8np_0eRYqXkoSNA",
"uploads": "qsdqsd1y8np_0eRYqXkoSNA"
},
"googlePlusUserId": "151...45515"
}
}
]
}
The playlist id of the uploads : items -> contentDetails -> uploads
Now you need to call the API a second time with youtube.playlistItems.list with the parameters :
part=snippet
playlistId=ID_OF_THE_PLAYLIST_UPLOADS
The result is like this :
{
"kind": "youtube#playlistItemListResponse",
"etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/bS4qNeqE0hEI-qb_r8hcbN9G1sE\"",
"nextPageToken": "CAUQAA",
"pageInfo": {
"totalResults": 38,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#playlistItem",
"etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/ItttPAEwALDI0QdLoylbdN6oHcY\"",
"id": "UUT2INYKRKg8bTaC4Z8-faCKSOt7nfZDHN",
"snippet": {
"publishedAt": "2014-08-12T09:45:41.000Z",
"channelId": "UCM1Bnpxipb8H4GJoITnJ0XQ",
"title": "Trollsky making a small wood carving knife",
"description": "Music by Witek Kulczycki\nhttps://itunes.apple.com/pl/album/monaghan-single/id905434557\nhttp://www.cdbaby.com/Artist/WitekKulczycki",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/bTD8U2fcG-Y/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/bTD8U2fcG-Y/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/bTD8U2fcG-Y/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/bTD8U2fcG-Y/sddefault.jpg",
"width": 640,
"height": 480
}
},
"channelTitle": "Trollskyy",
"playlistId": "UUM1Bnpxipb8H4GJoITnJ0XQ",
"position": 0,
"resourceId": {
"kind": "youtube#video",
"videoId": "bTD8U2fcG-Y"
}
}
},
...
The uploads are sort by date. Lastest upload is the top of the list.
Hope it's help !

How can I get a list of videos from a playlist in an auto-generated YouTube channel via the API?

YouTube has introduced auto-generated channels, for example http://www.youtube.com/channel/UCH-BBvNWh1CONPAjpeocGcw. From the channelId, I can use the API
to retrieve its associated playlists:
GET https://www.googleapis.com/youtube/v3/playlists?part=contentDetails&channelId=UCH-BBvNWh1CONPAjpeocGcw&key={YOUR_API_KEY}
gets, in part:
"items": [
{
"kind": "youtube#playlist",
"etag": "\"GbgM9_0DKhSLzW6BxAmfOJZH9RI/q_Rxfox9sHfH_r9g_LimnQeVsyU\"",
"id": "ALNb4maWNoT6RXC29sfG8iREznyAb9tqqJ",
"contentDetails": {
"itemCount": 95
}
},......
Each playlist has an id and an itemCount. When I use the playlistId, I get no items back:
GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&id=ALNb4maWNoT6RXC29sfG8iREznyAb9tqqJ&key={YOUR_API_KEY}
gets me
{
"kind": "youtube#playlistItemListResponse",
"etag": "\"GbgM9_0DKhSLzW6BxAmfOJZH9RI/3cxjRXf86G9z5Bg7rup3QfCgrxM\"",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 5
},
"items": [
]
}
Am I missing a step?
Solved my own problem. The playlistId should be the "playlistId" parameter, not "id".
GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=ALNb4maWNoT6RXC29sfG8iREznyAb9tqqJ&key={YOUR_API_KEY}

Resources