How do I get a YouTube video thumbnail from the YouTube API?

后端 未结 30 3291
Happy的楠姐
Happy的楠姐 2020-11-21 07:06

If I have a YouTube video URL, is there any way to use PHP and cURL to get the associated thumbnail from the YouTube API?

30条回答
  •  故里飘歌
    2020-11-21 07:49

    If you're using the public API, the best way to do it is using if statements.

    If the video is public or unlisted, you set the thumbnail using the URL method. If the video is private you use the API to get the thumbnail.

     Unlisted';
        }
        elseif($video_status == 'public'){
            $video_thumbnail = 'http://img.youtube.com/vi/'.$video_url.'/mqdefault.jpg';
            $video_status = ' Public';
        }
        elseif($video_status == 'private'){
            $video_thumbnail = $playlistItem['snippet']['thumbnails']['maxres']['url'];
            $video_status = ' Private';
        }
    

提交回复
热议问题