Getting all the videos (data) from a YouTube channel with the API seems a fairly common need right? Fair play to YouTube and Google as they’re going to make you put some thought into getting that result.
There is actually no straight up endpoint to achieve this, however you can retrieve (max 50) the latest videos from a channel and it comes with pagination through the parameter
?pageToken= with the token being found at
The best part is if there is no next page of results there is no
nextPageToken. Thus making the looping of results stop.
Getting all videos from a channel
Here is the code, make sure you put in the channel id and your YouTube API key
Essentially just a looping function, that if there is a
nextPageToken the function will self call itself. It will only stop when
nextPageToken is not found in the returned results.
Make sure to set it up with a database insert as repeating this code could bring your API limits to exhaustion.