gabrysiak
8/14/2014 - 7:50 PM

php_api_youtube_get_thumbnail.php

<?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']; 
    }