How to get thumbnail image content from thumbnail URL using You Tube API v3

476 Views Asked by At

I tried this in 2 ways:

First:

$url= "https://i.ytimg.com/vi/2ve6PEagFJc/maxresdefault.jpg";   
$curl = curl_init();  
curl_setopt($curl, CURLOPT_URL, (string)$url);  
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);   
curl_setopt($curl, CURLOPT_HEADER, false);   
$raw_contents = curl_exec($curl);//(it is returning **false** always)  
curl_close($curl);   

Second:

$url="https://i.ytimg.com/vi/2ve6PEagFJc/maxresdefault.jpg";  
echo $data=file_get_contents($url);   //(it is returning **false** always)

How can I get thumbnail image content using YouTube api v3 in php?

1

There are 1 best solutions below

0
On

This code worked for me

$url = "https://i.ytimg.com/vi/2ve6PEagFJc/maxresdefault.jpg";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$cont = curl_exec($ch);
curl_close($ch);
file_put_contents('/tmp/2ve6PEagFJc.jpg',print_r($cont,true));