Skip to content

Instantly share code, notes, and snippets.

@emersonbroga
Created November 21, 2012 19:48
Show Gist options
  • Save emersonbroga/4127215 to your computer and use it in GitHub Desktop.
Save emersonbroga/4127215 to your computer and use it in GitHub Desktop.
Get User Videos from Youtube
function getYoutubeVideos( $username, $limit = null)
{
$url = 'http://gdata.youtube.com/feeds/api/users/'.$username.'/uploads';
$feed = simplexml_load_file($url);
$videos = array();
$limit = ($limit === null ) ? count($feed->entry) : $limit;
$i = 0;
while( isset($feed->entry[$i]) && ( $i <= $limit )){
$video = $feed->entry[$i];
$current = array();
$current['title'] = (string) $video->title;
$current['url'] = (string) $video->link['href'];
$current['description'] = (string) $video->content;
parse_str($current['url'], $urlparts);
$current['code'] = current($urlparts);
array_push( $videos, (object) $current);
$i++;
}
return (object) $videos;
}
getYoutubeVideos('username');
/**
* @todo: Implement limit pagination, because youtube max limit is 50
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment