how do you get the fourth item in the YouTube API version3`

Hi,

I am working with the YouTube API and I want to be able to display the thumbnails and title for the first three results then for the rest just display the title.

Since version 3 doesn't have a start-index I don't know how to do it.

Maybe use Jquery to loop the first three and display the thumbnail and title then use another loop that starts on the fourth item and display just the  title?

Here is what I have so far.

Thanks,

 <script type="text/javascript">
      pid = '';
      $(document).ready(function(){
        $.get(
          "https://www.googleapis.com/youtube/v3/channels", {
            part: 'contentDetails',
            forUsername: 'mcdonalds',
            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){
                $("#container").append('<li style="list-style:none;"><a href="javascript:void(0);" onclick="javascript:getVids(pid, \'' + data.prevPageToken + '\');">&raquo; Prev Page<a/></li>');
              }
            }catch(err){
            }

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




<ul id="results" class="videos2" style="width:300px;"></ul>

<div id="container">
</div>

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.

Rainer JeschorCommented:
Hi,
just use the index which is passed to the each function and avoid multiple loops as this costs performance.
If index > 2 then display just the title otherwise the rest.
E.g.:
$.each(data.items, function(i, item){
              console.log(item);
              videoTitle = item.snippet.title;
			  if (i>2) {
			  output = '<li style="list-style:none;">' + videoTitle + '</li>';
			  } else {
				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);
            });

Open in new window

Have not fully tested this - but the general idea should work.

HTH
Rainer
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:
Thanks!!
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.