Last active
March 4, 2016 05:14
-
-
Save cergey-obr/f21170c6d2d12e9ee00d to your computer and use it in GitHub Desktop.
Получение изображения видео youtube
$id_video - id видео youtube
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function getYouTubeImg($id_video) { | |
$apiKey = 'AIzaSyCGlOkSZitdA33mnUhmW3hmqdPalusV5GQ'; | |
$url = 'https://www.googleapis.com/youtube/v3/videos?id='.$id_video.'&key='.$apiKey.'&part=snippet'; | |
$data = json_decode(file_get_contents($url), true); | |
$thumbnails = $data['items'][0]['snippet']['thumbnails']; | |
$thumb = array_pop($thumbnails); | |
$name = $_SERVER['DOCUMENT_ROOT'].'/images/youtube/'.$id_video.'_image.jpg'; | |
if (file_exists($name)) { | |
return str_replace('./', '/', $name); | |
} else { | |
copy($thumb['url'], $name); | |
return str_replace('./', '/', $name); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment