How to get a youtube playlist thumbnail?

有没有办法让YouTube播放列表缩略图像你如何获得视频的缩略图一样,在这里解释:如何从YouTube API获得YouTube视频缩略图?


With the YouTube API v3, you can get the playlist thumbnail using their v3/playlists endpoint and drilling down to items.snippet.thumbnails.high.url

For the following playlist:

https://www.youtube.com/playlist?list=PL50C17441DA8A565D

YouTube's API explorer has a playlist endpoint:

https://developers.google.com/youtube/v3/docs/playlists/list

This is the API call:

GET https://www.googleapis.com/youtube/v3/playlists?part=snippet&id=PL50C17441DA8A565D&key={YOUR_API_KEY}

And here is the response:

    {
     "kind": "youtube#playlistListResponse",
     "items": [
      {
       "kind": "youtube#playlist",
       "id": "PL50C17441DA8A565D",
       "snippet": {
        "title": "Jay Chou Playlist",
        "thumbnails": {
         "default": {
          "url": "https://i.ytimg.com/vi/kGbDymJ75PU/default.jpg",
          "width": 120,
          "height": 90
         },
         "medium": {
          "url": "https://i.ytimg.com/vi/kGbDymJ75PU/mqdefault.jpg",
          "width": 320,
          "height": 180
         },
         "high": {
          "url": "https://i.ytimg.com/vi/kGbDymJ75PU/hqdefault.jpg",
          "width": 480,
          "height": 360
         }
        },
        "channelTitle": "it23"
       }
      }
     ]
    }

This is what worked for me. Similar to the other post regarding playlist items but I just changed the API call. Hope it helps.

//get playlist itmes

$data = file_get_contents("https://www.googleapis.com/youtube/v3/playlistItems?key=< YOUR API KEY >&part=snippet&playlistId="<Put your playlist id here>");

//decode response from youtube

$json = json_decode($data);

//if you want to see the full response use print_r($json);

//each items in the response corresponds to a video in the playlist so lets get the first video (items[0]) get its snippet and corresponding thumbnails and we will take the url for the default size. If you want the second video use items [1] etc.

$video_thumbnail = $json->items[0]->snippet->thumbnails->default->url;

//set the videos alt tag as the snippet description

$video_alt = $json->items[0]->snippet->description; 

//echo the image url into an image tag

echo '<img src="'. $video_thumbnail .'" alt="'. $video_alt .'" />';

There is no API for this purpose. Here is a workaround I can think of.

1) What youtube playlist thumbnail is? Played around with my account and seems the rule is as below:

if playlist has 5+ videos
  thumbnail = first 5 video images
else if playlist has 1+ videos
  thumbnail = all video images
else shows this list is empty

2) Then you can use the same way to get video thumbnails.

3) combine the images either on the client side (some CSS) or server side

链接地址: http://www.djcxy.com/p/4930.html

上一篇: YouTube API可以获取频道上的所有视频

下一篇: 如何获得YouTube播放列表缩略图?