0

I'm trying to get videos from Youtube playlists. I manage to get only 26 in playlists with 50+ videos. I noticed Youtube loads only 26 by default and other videos are loaded to page by scrolling down the playlist. EXAMPLE

The problem is that nextPageToken is undefined on second request, but by manually going to the playlist you can load more videos.

Is there any way to get remaining videos from playlists?

Here is what I'm doing: JSFiddle

function getVids(playlistId, nextPageToken){
    $.get(
        "https://www.googleapis.com/youtube/v3/playlistItems",{
        part : 'snippet', 
        maxResults : 20,
        playlistId : playlistId,
        pageToken: nextPageToken,
        key: '{API_KEY}'},
        function(data) {
            console.log(data.nextPageToken);
            console.log(data.items.length);
            getVids(playlistId, data.nextPageToken);
        }
    );
}

getVids('RDaUWYDaVp92I');
mhlavacka
  • 691
  • 11
  • 25

1 Answers1

0

A missing .relatedPlaylists may have caused your nextpageToken undefined error. According to this post, using that may help like: playlistId = response.result.items[0].contentDetails.relatedPlaylists.uploads;

To try retrieving all videos try this as mentioned in this post:

https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=PLB03EA9545DD188C3&key=MY_API_KEY

And here is the official Google Docs with regard to retrieving videos from playlists.

Community
  • 1
  • 1
ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56