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

后端 未结 30 2701
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:51

    I have used YouTube thumbnails in this way:

    $url = 'http://img.youtube.com/vi/' . $youtubeId . '/0.jpg';
    $img = dirname(__FILE__) . '/youtubeThumbnail_'  . $youtubeId . '.jpg';
    file_put_contents($img, file_get_contents($url));
    

    Remember YouTube prevents to include images directly from their server.

提交回复
热议问题