Config Router

  • Google Sheets
  • CCNA Online training
    • CCNA
  • CISCO Lab Guides
    • CCNA Security Lab Manual With Solutions
    • CCNP Route Lab Manual with Solutions
    • CCNP Switch Lab Manual with Solutions
  • Juniper
  • Linux
  • DevOps Tutorials
  • Python Array
You are here: Home / How do I get a YouTube video thumbnail from the YouTube API?

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

October 8, 2021 by James Palmer

Each YouTube video has four generated images. They are predictably formatted as follows:
https://img.youtube.com/vi//0.jpg
https://img.youtube.com/vi//1.jpg
https://img.youtube.com/vi//2.jpg
https://img.youtube.com/vi//3.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//default.jpg

For the high quality version of the thumbnail use a URL similar to this:
https://img.youtube.com/vi//hqdefault.jpg

There is also a medium quality version of the thumbnail, using a URL similar to the HQ:
https://img.youtube.com/vi//mqdefault.jpg

For the standard definition version of the thumbnail, use a URL similar to this:
https://img.youtube.com/vi//sddefault.jpg

For the maximum resolution version of the thumbnail use a URL similar to this:
https://img.youtube.com/vi//maxresdefault.jpg

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.
Alternatively, you can use the YouTube Data API (v3) to get thumbnail images.

You can use YouTube Data API to retrieve video thumbnails, caption, description, rating, statistics and more. API version 3 requires a key*. Obtain the key and create a videos: list request:
https://www.googleapis.com/youtube/v3/videos?key=YOUR_API_KEY&part=snippet&id=VIDEO_ID

Example PHP Code
$data = file_get_contents(“https://www.googleapis.com/youtube/v3/videos?key=YOUR_API_KEY&part=snippet&id=T0Jqdjbed40”);
$json = json_decode($data);
var_dump($json->items[0]->snippet->thumbnails);

Output
object(stdClass)#5 (5) {
[“default”]=>
object(stdClass)#6 (3) {
[“url”]=>
string(46) “https://i.ytimg.com/vi/T0Jqdjbed40/default.jpg”
[“width”]=>
int(120)
[“height”]=>
int(90)
}
[“medium”]=>
object(stdClass)#7 (3) {
[“url”]=>
string(48) “https://i.ytimg.com/vi/T0Jqdjbed40/mqdefault.jpg”
[“width”]=>
int(320)
[“height”]=>
int(180)
}
[“high”]=>
object(stdClass)#8 (3) {
[“url”]=>
string(48) “https://i.ytimg.com/vi/T0Jqdjbed40/hqdefault.jpg”
[“width”]=>
int(480)
[“height”]=>
int(360)
}
[“standard”]=>
object(stdClass)#9 (3) {
[“url”]=>
string(48) “https://i.ytimg.com/vi/T0Jqdjbed40/sddefault.jpg”
[“width”]=>
int(640)
[“height”]=>
int(480)
}
[“maxres”]=>
object(stdClass)#10 (3) {
[“url”]=>
string(52) “https://i.ytimg.com/vi/T0Jqdjbed40/maxresdefault.jpg”
[“width”]=>
int(1280)
[“height”]=>
int(720)
}
}

* Not only that you need a key, you might be asked for billing information depending on the number of API requests you plan to make. However, few million requests per day are free.
Source article.

Related

Filed Under: Uncategorized

Recent Posts

  • How do I give user access to Jenkins?
  • What is docker volume command?
  • What is the date format in Unix?
  • What is the difference between ARG and ENV Docker?
  • What is rsync command Linux?
  • How to Add Music to Snapchat 2021 Android? | How to Search, Add, Share Songs on Snapchat Story?
  • How to Enable Snapchat Notifications for Android & iPhone? | Steps to Turn on Snapchat Bitmoji Notification
  • Easy Methods to Fix Snapchat Camera Not Working Black Screen Issue | Reasons & Troubleshooting Tips to Solve Snapchat Camera Problems
  • Detailed Procedure for How to Update Snapchat on iOS 14 for Free
  • What is Snapchat Spotlight Feature? How to Make a Spotlight on Snapchat?
  • Snapchat Hack Tutorial 2021: Can I hack a Snapchat Account without them knowing?

Copyright © 2023 · News Pro Theme on Genesis Framework · WordPress · Log in