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"
}
]
}
totalResults
andresultsPerPage
. Normally if you count items of your playlist with the YouTube interface items returned, the counts match. So for getting all elements of a playlist exceedingmaxResults
items, just based your algorithm on the existence and the change ofnextPageToken
NB: I don't know whether or not there is an official comment about this unprecise values (totalResults
andresultsPerPage
) in YouTube Data API v3 documentation. – Benjamin Loisonitems.length
as you suggest, is that it only gives me the items per page (the number of items in that response). However, what I need is the total possible items in the playlist. Interesting that you saypageInfo.totalResults
can’t be trusted, do you have any examples? – SamtotalResults
andresultsPerPage
is "officially" approximative. I stopped looking for logics behind YouTube Data API v3. I am just giving people a way to get the data they are looking for. If you want the total possible items in the playlist you can get all items from the API and count them or if you don't want to spend too much of your data you can use a shell with for instance:curl -s https://www.youtube.com/playlist?list=PLAYLIST_ID | grep -F '"stats":[{"runs":[{"text":"'
– Benjamin Loison