Search code examples
apiyoutubeplaylist

How to get video title and thumbnail from YouTube Playlist


I am trying to get Thumbnails, titles, and their description from YouTube Playlist. So, far I am able to get thumbnails but not sure how can I get titles and description. Here is my code:

HTML:

<ul id="thumbnail"> </ul>

Script.js:

            var maxVideos = 5;
              $(document).ready(function(){
              $.get(
                "https://www.googleapis.com/youtube/v3/playlistItems",{
                  part: 'contentDetails,snippet',
                  playlistId:'PLJYHm_ZxWCKnQmapkDs7x47jkr-nw3l50',
                  kind: 'youtube#videoListResponse',
                  maxResults: maxVideos,
                  regionCode: 'IN',
                  key: 'AIzaSyDI4rWo_wVAxRZEIgF6_8sRZDj8OCOZZ38'},
                  function(data){
                    var output;
                    $.each(data.items, function(i, item){
                      console.log(item);
                            thumb = item.snippet.thumbnails.high.url;
                      output = '<div id="img"><img src="' + thumb + '"></div>';
                      $('#thumbnail').append(output);
                    })

                  }
                );
            });

Here is the result I am getting:

enter image description here


Solution

  • As used

    thumb = item.snippet.thumbnails.high.url;
    

    just do some changes after snippet

    as

    title= item.snippet.title;
    description= item.snippet.description;
    

    I hope it really help you.

    You can also go through YouTube API explorer for more details