Fetch YouTube Video Thumbnail Image free Using PHP

To day let’s discuss how to fetch the youtube video thumbnail image using php.

First we need youtube API Keys From Google developer Console.

Then use this code to get the Thumbnail Image

<?php

$error=0;
$youtube_video_response=array();
$search="f58IXhh3fvQ";
if(!empty($_POST['search'])){
  $search=$_POST['search'];
}
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://www.googleapis.com/youtube/v3/videos?key=AIzaSyBELBmlaJ7xmNPHiKklS91Sj4-scm7uesI&part=snippet&id=".$search,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
));

$response = curl_exec($curl);
curl_close($curl);
$youtube_video_response=json_decode($response);

if(empty($youtube_video_response->items)){
    $error=1; 
}
?>


Response:



{
  "kind": "youtube#videoListResponse",
  "etag": "E0ug3SQ0pdeceT-fYcKirPQBO64",
  "items": [
    {
      "kind": "youtube#video",
      "etag": "Rb_gtDPxa18r39Oas_mS7qCt_7g",
      "id": "f58IXhh3fvQ",
      "snippet": {
        "publishedAt": "2020-05-11T06:38:37Z",
        "channelId": "UCJx8_CPFQKtjBT7akr1GLWQ",
        "title": "HTML Introduction (In Hindi) | HTML Structure | Lesson - 1 | HTML क्या होता हे ?",
        "description": "In this video we will learn about basic html structure. how you can make your own basic webpage with manual html coding with simple notepad.",
        "thumbnails": {
          "default": {
            "url": "https://i.ytimg.com/vi/f58IXhh3fvQ/default.jpg",
            "width": 120,
            "height": 90
          },
          "medium": {
            "url": "https://i.ytimg.com/vi/f58IXhh3fvQ/mqdefault.jpg",
            "width": 320,
            "height": 180
          },
          "high": {
            "url": "https://i.ytimg.com/vi/f58IXhh3fvQ/hqdefault.jpg",
            "width": 480,
            "height": 360
          },
          "standard": {
            "url": "https://i.ytimg.com/vi/f58IXhh3fvQ/sddefault.jpg",
            "width": 640,
            "height": 480
          },
          "maxres": {
            "url": "https://i.ytimg.com/vi/f58IXhh3fvQ/maxresdefault.jpg",
            "width": 1280,
            "height": 720
          }
        },
        "channelTitle": "TECH it eazy",
        "tags": [
          "What is HTML in Hindi",
          "Learn HTML Online",
          "Basic Learning",
          "structure of html in hindi",
          "html tags in hindi",
          "how to use html in hindi",
          "Computer",
          "Coding",
          "Web Development",
          "Web Design",
          "PHP",
          "Beginers",
          "Any Can Learn",
          "How to",
          "Tech it eazy"
        ],
        "categoryId": "28",
        "liveBroadcastContent": "none",
        "localized": {
          "title": "HTML Introduction (In Hindi) | HTML Structure | Lesson - 1 | HTML क्या होता हे ?",
          "description": "In this video we will learn about basic html structure. how you can make your own basic webpage with manual html coding with simple notepad."
        },
        "defaultAudioLanguage": "hi"
      }
    }
  ],
  "pageInfo": {
    "totalResults": 1,
    "resultsPerPage": 1
  }
}

Add a Comment

Your email address will not be published. Required fields are marked *