User3120
User3120

Reputation: 30

YouTube Data API not returning all Videos in Channel

I'm trying to get the list of all videos in a channel, using the playlistItems list to get all the videos by passing the playlistId. Example -

Get the ID of your channel's uploads playlist using the channels.list API call: GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id={YOUR_CHANNEL_ID}&key={YOUR_API_KEY}

Get the videos from the uploads playlist using the playlistItems.list call: GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId={YOUR_PLAYLIST_ID}&key={YOUR_API_KEY}

And I'm using the next page token to get to the pages and loop through till I keep getting the next page token.

But I noticed that, this is very inconsistent. The above doesn't return all the videos of the channel. All the missing videos are available on YouTube and also return valid data when using the VideosList end point passing in their videoIds.

Till now I have noticed the same videos are missing every time and they were available in the past. Is this a known issue with the YouTube APIs?

And is there any other way to get all the videos of channels of all statuses (public, private, unlisted). Even large channels which can have 50k+ videos.

Upvotes: 1

Views: 1666

Answers (2)

Anuj Jadhav
Anuj Jadhav

Reputation: 1

Similar problem with solution: How to avoid omissions in video information acquisition when using the YouTube Data API?

I have personally used this approach and it worked for me. The approach: Step 1: Obtain the ID of the Uploads Playlist of a Channel. Step 2: Retrieve All IDs of Videos of a Playlist.

Upvotes: 0

Benjamin Loison
Benjamin Loison

Reputation: 5642

  1. https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=3&playlistId={YOUR_PLAYLIST_ID}&key={YOUR_API_KEY} won't return all videos because of maxResults=3 you can increase maxResults up to 50. And after having get the first 50 results (if there are more than 50) a new newPageToken is provided which you have to use by appending to the previous URL &pageToken=THE_NEW_PAGE_TOKEN and so on. If it doesn't work anyway the next point may interest you.

  2. It is known that YouTube playlists are limited to 20 000 videos so recovering videos from channels with more 50 000 videos won't work as usual and there isn't any YouTube Data API v3 endpoint which will recovers all videos of these channels. However as you browse the Videos tab of a YouTube channel with more than 50 000 videos you will discover all the missing videos from the PlayList method. You can automatize this at a low level by using curl for instance. Here you may find a Python code doing exactly this.

Upvotes: 1

Related Questions