I found this code in a YouTube video (thanks to the partner) and have managed to make a few custom changes to it. All this does is list a number of embedded videos. I've limited it to 4 so as to fit in one page but am having difficulty understanding how to get the next set of 4 videos.

I am no programmer but I believe this is in .js being called by an HTML page as shown below

 var channelName = 'Ruff8866';
 var APIkey = 'MY API KEY';

 $(document).ready(function(){
        $.get(
         "https://www.googleapis.com/youtube/v3/channels",{
            part: 'contentDetails',
            forUsername: channelName,
            key: APIkey},
            function(data){
                $.each(data.items, function(i, item){
                    console.log(item);
                    pid = item.contentDetails.relatedPlaylists.uploads;
                    getVids(pid);
                })
            }
    );

    function getVids(pid){
        $.get(
        "https://www.googleapis.com/youtube/v3/playlistItems",{
            part: 'snippet',
            maxResults: 4,
            playlistId: pid,
            key: APIkey},
            function(data){
                var output;
                $.each(data.items, function(i, item){
                    console.log(item);
                    videoTitle = item.snippet.title;
                    videoId = item.snippet.resourceId.videoId;
                    videoViews = item.snippet.resourceId.viewCount;

                    output = '<table>';
                    output = output + ' <tr>';
                    output = output + '  <td><iframe allow=";" allowfullscreen="" frameborder="0" width="300" height="185" src="https://www.youtube.com/embed/'+videoId+'"></iframe></td>';
                    output = output + ' </tr>';
                    output = output + '</table>';

//                  output = videoId+'<br>';

                    $('#results').append(output);
                })
            }
    );
    }
 }); 

Would be nice to also include number of views per video.

0 Answers