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

后端 未结 30 2685
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:37

    If you want to get rid of the "black bars" and do it like YouTube does it, you can use:

    https://i.ytimg.com/vi_webp/

    And if you can't use the .webp file extension you can do it like this:

    https://i.ytimg.com/vi/

    Also, if you need the unscaled version, use maxresdefault instead of mqdefault.

    Note: I'm not sure about the aspect ratio if you're planning to use maxresdefault.

提交回复
热议问题