如何从YouTube API获取YouTube视频缩略图? [英] How do I get a YouTube video thumbnail from the YouTube API?

查看:783
本文介绍了如何从YouTube API获取YouTube视频缩略图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有YouTube视频网址,是否有任何方法可以使用PHP和cURL从YouTube API获取相关的缩略图?

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?

推荐答案

每个YouTube视频都有4张生成的图片。它们的格式如下:

Each YouTube video has 4 generated images. They are predictably formatted as follows:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg

列表中的第一个是全尺寸图像,其他是缩略图。默认缩略图(即 1.jpg 2.jpg 3 .jpg )是:

The first one in the list is a full size image and others are thumbnail images. The default thumbnail image (ie. one of 1.jpg, 2.jpg, 3.jpg) is:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg

缩略图使用类似于此的网址:

For the high quality version of the thumbnail use a url similar to this:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg

还有一个中等质量版本的缩略图,使用类似于HQ的网址:

There is also a medium quality version of the thumbnail, using a url similar to the HQ:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg

对于缩略图的标准定义版本,类似于此的网址:

For the standard definition version of the thumbnail, use a url similar to this:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/sddefault.jpg

缩略图的最大分辨率版本使用类似于此的网址:

For the maximum resolution version of the thumbnail use a url similar to this:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg

所有上述网址都可以通过http。此外,稍微缩短的主机名 i3.ytimg.com 可代替示例网址中的 img.youtube.com

All of the above urls are available over http too. Additionally, the slightly shorter hostname i3.ytimg.com works in place of img.youtube.com in the example urls above.

或者,您也可以使用 YouTube Data API(v3)以获取缩略图。

Alternatively, you can use the YouTube Data API (v3) to get thumbnail images.

这篇关于如何从YouTube API获取YouTube视频缩略图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆