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

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

问题描述

如果我有一个 YouTube 视频 URL,有没有办法使用 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 视频都有四个生成的图像.它们的格式可预测如下:

Each YouTube video has four 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.jpg2.jpg3.jpg 之一)为:

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

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

对于缩略图的高质量版本,请使用类似于此的 URL:

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 的 URL:

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

对于缩略图的标准定义版本,请使用类似于以下内容的 URL:

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

对于缩略图的最大分辨率版本,请使用类似于以下内容的 URL:

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

上述所有 URL 也可通过 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 数据 API (v3) 来获取缩略图.

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

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

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