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

后端 未结 30 3268
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:40

    Here is a simple function I created for getting the thumbnails. It is easy to understand and use.

    $link is the YouTube link copied exactly as it is in the browser, for example, https://www.youtube.com/watch?v=BQ0mxQXmLsk

    function get_youtube_thumb($link){
        $new = str_replace('https://www.youtube.com/watch?v=', '', $link);
        $thumbnail = 'https://img.youtube.com/vi/' . $new . '/0.jpg';
        return $thumbnail;
    }
    

提交回复
热议问题