title: Getting Youtube view counts for several videos using APIv3 (jquery)
body: <p>I'm trying to create a youtube social feed that includes the video, title, description, date, and view count. I've got everything to work except for the last one, view count. I've been able to get the view counts to show up but they are always out of order and I'm lost on how to make them match up to their respective videos. I used this video as an initial tutorial: [<a href="https://www.youtube.com/watch?v=jdqsiFw74Jk][1]" rel="nofollow">https://www.youtube.com/watch?v=jdqsiFw74Jk][1]</a> It got me this far, but now I'm lost again. Here is my code via code pen: [<a href="http://codepen.io/ThatsMyJams/pen/EjZWex][2]" rel="nofollow">http://codepen.io/ThatsMyJams/pen/EjZWex][2]</a></p>
  
  <p>here is my html:</p>
  
  <pre><code>&lt;div id="container"&gt;
    &lt;h2&gt;Results:&lt;/h2&gt;
    &lt;ul id="results"&gt;&lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and here is my javascript:</p>
  
  <pre><code>var yourApiKey = 'AIzaSyDpY9FHgp7EvnDr5mGrxWwKgUBtfM8l5PE';
  
      var channelName = 'GoogleDevelopers';
      var vidCount = 5;
      var vidHeight = 275;
      var vidWidth = 400;
  
      $(document).ready(function(){
          $.get(
              "https://www.googleapis.com/youtube/v3/channels", {
                  part: 'contentDetails',
                  forUsername: channelName,
                  key: yourApiKey},
              function(data){
                  $.each(data.items, function(i, item){
                      console.log(item);
                      playerID = item.contentDetails.relatedPlaylists.uploads;
                      getVids(playerID);
                  })
              }
          );
          function getVids() {
              $.get(
                  "https://www.googleapis.com/youtube/v3/playlistItems", {
                      part: 'snippet',
                      maxResults: vidCount,
                      playlistId: playerID,
                      key: 'AIzaSyDpY9FHgp7EvnDr5mGrxWwKgUBtfM8l5PE'},
                  function(data){
                      var output;
                      $.each(data.items, function(i, item){
                          console.log(item);
                          vidTitle = item.snippet.title;
                          videoID = item.snippet.resourceId.videoId;
                          vidDate = item.snippet.publishedAt;
                          vidDesc = item.snippet.description;      
  
                          output = '&lt;li&gt;'+vidTitle+'&lt;span class="date"&gt;'+vidDate+'&lt;/span&gt;&lt;p class="description"&gt;'+vidDesc+'&lt;/p&gt;&lt;iframe height="'+vidHeight+'" width ="'+vidWidth+'" src=\"//www.youtube.com/embed/'+videoID+'\"&gt;&lt;/iframe&gt;&lt;/li&gt;';
  
                          //append to results list
                          $('#results').append(output);
                          getViews(videoID[i]);
                      })
                  }
              );
          }
          function getViews() {
              $.get(
                  "https://www.googleapis.com/youtube/v3/videos", {
                      part: 'statistics',
                      id: videoID,
                      key: 'AIzaSyDpY9FHgp7EvnDr5mGrxWwKgUBtfM8l5PE'},
                  function(data){
                      var output2;
                      $.each(data.items, function(i, item){
                          vidViews = item.statistics.viewCount;
  
                          output2 = '&lt;span class="views"&gt;'+vidViews+'&lt;/span&gt;'
                          //append to results list
                          $('#results li').each(function() {
                              $(this).append(output2);
                          });
                      })
                  }
              );
          }
      });
  </code></pre>
  
  <p>I just want to get the viewCount for each video and insert it into the html much like I did for the title, date, etc. Any help would be greatly appreciated :)</p>