Thomas Beyer
Thomas Beyer

Reputation: 81

Youtube API v3 get every Video ID from given channel

Currently I'm using this in order to get a list of videoIDs from a given channel:

GET https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId=CHANNEL_ID&type=video&maxResults=50&key=API_KEY

This works, however the channel I want to get the videos from has a lot more than 50 Videos online. I already looked at this issue YouTube API to fetch all videos on a channel but every solution again online fetches 50 Videos max.

How can I get every video and not just 50?

Upvotes: 4

Views: 1883

Answers (2)

Dan Thomas
Dan Thomas

Reputation: 65

Here's a video from the YouTube Developers channel that really helped me with this: https://youtu.be/RjUlmco7v2M. It's directed towards people migrating from v2 to v3 (which I wasn't), but I kept watching and learned quite a few things.

Upvotes: 0

Thomas Beyer
Thomas Beyer

Reputation: 81

So I got a solution:

(1) First, I use https://www.googleapis.com/youtube/v3/channels?id=CHANNEL_ID&key=API_KEY&part=contentDetails to get the id of the Uploads Playlist.

(2) By using https://www.googleapis.com/youtube/v3/playlistItems?playlistId=UPLOAD_ID&key=API_KEY&part=snippet&maxResults=50 I get the first 50 results and a pageToken.

(3) With the token I can collect the IDs from the next pages: https://www.googleapis.com/youtube/v3/playlistItems?playlistId=UPLOAD_ID&key=API_KEY&part=snippet&pageToken=PAGE_TOKEN&maxResults=50

(4) By using a recursive method, I can use the next Token I get from (3) to scan the next page.

Upvotes: 4

Related Questions