0

I'm trying to fetch all the videos in a channel. I've noticed an inconsistency between the number of results returned by /search and /playlistItems.

When using /search, totalResults = 20 and 20 items are returned.

https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCaLCI9770qY9hGRmdZgVV-g&maxResults=50&type=video&key={YOUR_API_KEY}

However, when using /playlistItems (using the approach here), totalResults = 23 but items contains only 20 items.

https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=UUaLCI9770qY9hGRmdZgVV-g&key={YOUR_API_KEY}

The YouTube Channel currently shows 20 videos on the website: https://www.youtube.com/user/1957fenderstrat/videos

Is it possible that totalResults in /playlistItems is counting deleted videos?

Does anybody have a solution to getting all the videos of a channel, without incurring the higher cost of a call to /search?

Potentially related:

youtube api playlistitems deleted videos

EDIT :

I just noticed that the channel statistics also returns a videoCount of 23.

https://www.googleapis.com/youtube/v3/channels?part=statistics&id=UCaLCI9770qY9hGRmdZgVV-g&maxResults=50&key={YOUR_API_KEY}

Community
  • 1
  • 1
user666
  • 5,231
  • 2
  • 26
  • 35
  • I think you cannot get the same number of results in this two request, because the channel and playlist is not the same, or the videos inside of the two. So what is your real question? What do you want to achieve with this? – KENdi Jul 14 '16 at 15:09
  • I'm trying to get all the videos in a channel, using a call to `/playlistItems`. My issue is that the number of items and the `totalResults` appear to be different, making my code think I'm missing videos. – user666 Jul 14 '16 at 18:07

1 Answers1

0

In my experience the Seach call is not meant to be used to enumerate videos from a channel.

Despite accepting a channelId the results are not even guaranteed to be only from that channel. Also despite the total items advertised, the search call can stop returning items after a few 100 results. (I've seen people use the publishedBefore parameter to try and make it get more, but it is usually not reliable.)

Your best bet is to use the playlistItems list call. Total may not be accurate to the point, so only use the page tokens. In systems as large and distributed as YouTube, totals can be a bit off occasionally due to many reasons.

Also note that search call costs 100 quota points and playlistItems costs 1 point.

Madushan
  • 6,977
  • 31
  • 79