Friday, 29 April 2016

How To Fetch All the uploads Of a Channel Of your Wise using YouTube Data API v3 ?????




In this post , I would like to share  ,how could anyone can fetch all the channel uploads without moving through all the videos to find the right video for you to watch.

This requires Simple steps which are as follows :

1. firstly, you need to sign-in to the Google Developers Console with any of yours Gmail acccount.

2. Then create a project over YouTube Data API.

3. Then  You guys need to a need to create an API key.

and you are set to go!!!..

This entire thing is only based on JAVASCRIPT. Go the Entire Code.. ANY QUESTION YOU HAVE JUST COMMENT IT..


<!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 : 'GoogleDevelopers',  /*This is the channel name from which you want to fetch data */
key : 'AIzaSyBtk260O3v15xe6lSTHMlYOrLXf8XPGLw8' /* This is the API key..you guys need to change it with yours API Key*/
          },
        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 : 'AIzaSyBtk260O3v15xe6lSTHMlYOrLXf8XPGLw8'
        }
     
        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);
            });

'<br/>'
'<br/>'

            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){
            }

'<br/>'
'<br/>'

            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>


1 comment: