how do you show more than 50 results on youtube api (pagination)

Hi,

I am working with the youtube api v3 and cant figure out how to show more than 50 results.

I think it has to do with pagination.

Here is my code so far.

I know it has to do with search.list but I can't figure out how to create the function around it.

Thanks,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
 <script type="text/javascript">
$(document).ready(function() {
	$.get(
	"https://www.googleapis.com/youtube/v3/channels",{
		part:'contentDetails',
		forUsername:'doctorscompany',
		key: 'AIzaSyB7oqNYxEGnskHEpKHSCbIH_-VI4_sJkzg'},
		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:50,
		playlistId: pid,
		key: 'AIzaSyB7oqNYxEGnskHEpKHSCbIH_-VI4_sJkzg'},
		function(data) {		
			 var output;			
			$.each(data.items,function(i, item) {
				console.log(item);
				videoTitle = item.snippet.title;
				 rvideoID = item.snippet.resourceId.videoId;
				 vidThumburl =  item.snippet.thumbnails.high.url;				                   				
				 output = '<li style="list-style:none;"><a class="videos2 video" href="https://www.youtube.com/watch?v='+rvideoID+'">'+videoTitle+'<a/></li>';
				 				  
				  //Append to results list
				  $('#results').append(output);				
			})
			
		}
	);
	}	
});
</script>
</head>

<body>
<div id="container">
<ul id="results"></ul>
</div>
   
</body>
</html>

Open in new window

smfmetro10Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mukesh YadavFull Stack DeveloperCommented:
Means you wants to add prev and next buttons to load next and previous set of videos?
0
Mukesh YadavFull Stack DeveloperCommented:
Try this code:-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script type="text/javascript">
      pid = '';
      $(document).ready(function(){
        $.get(
          "https://www.googleapis.com/youtube/v3/channels", {
            part: 'contentDetails',
            forUsername: 'doctorscompany',
            key: 'AIzaSyB7oqNYxEGnskHEpKHSCbIH_-VI4_sJkzg'
          },
        function(data){
          $.each(data.items, function(i, item){
            console.log(item);
            pid = item.contentDetails.relatedPlaylists.uploads;
            getVids(pid);
          })
        });

      });
      function getVids(pid, pageToken){
        var data = {
          part: 'snippet',
          maxResults: 50,
          playlistId: pid,
          key: 'AIzaSyB7oqNYxEGnskHEpKHSCbIH_-VI4_sJkzg'
        }
        
        try{
          if(pageToken){
            data["pageToken"] = pageToken;
          }
        }catch(err){
        }

        $.get(
          "https://www.googleapis.com/youtube/v3/playlistItems", data,
          function(data){
            var output;

            $('#results').html("");
            $.each(data.items, function(i, item){
              console.log(item);
              videoTitle = item.snippet.title;
              rvideoID = item.snippet.resourceId.videoId;
              vidThumburl = item.snippet.thumbnails.high.url;
              output = '<li style="list-style:none;"><a class="videos2 video" href="https://www.youtube.com/watch?v=' + rvideoID + '">' + videoTitle + '<a/></li>';
              //Append to results list
              $('#results').append(output);
            });

            try{
              if(data.prevPageToken){
                $("#results").append('<li style="list-style:none;"><a class="" href="javascript:void(0);" onclick="javascript:getVids(pid, \'' + data.prevPageToken + '\');">&raquo; Prev Page<a/></li>');
              }
            }catch(err){
            }

            try{
              if(data.nextPageToken){
                $("#results").append('<li style="list-style:none;"><a class="" href="javascript:void(0);" onclick="javascript:getVids(pid, \'' + data.nextPageToken + '\');">Next Page &laquo;<a/></li>');
              }
            }catch(err){
            }
          });
      }
    </script>
  </head>
  <body>
    <div id="container">
      <ul id="results"></ul>
    </div>

  </body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
smfmetro10Author Commented:
Outstanding!! Thank you so much!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.