Created
November 21, 2012 19:48
-
-
Save emersonbroga/4127215 to your computer and use it in GitHub Desktop.
Get User Videos from Youtube
This file contains hidden or 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
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