Skip to content

Instantly share code, notes, and snippets.

@gabrysiak
Created August 14, 2014 19:50
Show Gist options
  • Save gabrysiak/18c4095fea852722ebca to your computer and use it in GitHub Desktop.
Save gabrysiak/18c4095fea852722ebca to your computer and use it in GitHub Desktop.
<?php
/**
* Youtube API get thumbnail using Youtube username
* @param mixed $client Youtube username
* @return mixed Thumbnail src attribute
*/
public static function get_yt_thumbnail($client)
{
$feed1 = 'https://gdata.youtube.com/feeds/api/users/'.$client.'? fields=media:thumbnail';
// read feed into SimpleXML object
$entry2 = simplexml_load_file($feed1);
// get nodes in media: namespace for media information
$media = $entry2->children('http://search.yahoo.com/mrss/');
$attrs = $media->thumbnail[0]->attributes();
return $thumbnail = $attrs['url'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment