Reputation: 878
I am running a query on my own youtube channel to retrieve all the video titles. I have 680 videos but can only get about half of them. What I have done is create a code that iterates all the years since creation of the channel and within a year uses the pageTokens to go through the packs of 50 videos.
So a query would look like this:
https://www.googleapis.com/youtube/v3/search?key={XXXXX}&channelId={XXXXX}&part=snippet,id&order=date&type=video&maxResults=50&publishedAfter=2018-01-01T00:00:00Z&publishedBefore=2019-01-01T00:00:00Z&pageToken=CDIQAA
In the results for these queries, I get the indication that there are the following contents:
array (
'totalResults' => 321,
'resultsPerPage' => 50,
),
Iterating through the pages, I get 2 pages filled with 50 items, then another one where the results show as well 'resultsPerPage' => 50,
but contains only 35 videos, the rest for that year have 0 "items" in the JSON data. So the pages in question only give 135 results back instead of the 321. Once I switch to the next year, I get again 2 pages of full results, then one with some missing and then empty ones.
Any idea what could be wrong?
here is an excerpt of the last JSON data set:
array (
'kind' => 'youtube#searchListResponse',
'etag' => '"XpPGQXPnxQJhLgs6enD_n8JR4Qk/IsJyhRyDQ6qMmAHldktSRzEN2qs"',
'nextPageToken' => 'CJYBEAA',
'prevPageToken' => 'CGQQAQ',
'regionCode' => 'DE',
'pageInfo' =>
array (
'totalResults' => 321,
'resultsPerPage' => 50,
),
'items' =>
array (
0 =>
[..contents..]
35 =>
[..last content and closing brackets..]
Upvotes: 1
Views: 623
Reputation: 6985
If you want to get the entire video list of a given channel without any omissions, I suggest you to use PlaylistItems endpoint instead, queried for the given channel's uploads list by passing a proper value to the endpoint's playlistId parameter.
A given channel's uploads playlistId is obtained upon querying the channel's own endpoint. The needed ID is to be found at .items.contentDetails.relatedPlaylists.uploads
. Usually, an channel ID and its corresponding uploads playlist ID are related by s/^UC([0-9a-zA-Z_-]{22})$/UU\1/
.
One more remark: your should be aware of the difference between a video's published time and upload time.
Upvotes: 2