Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get complete playlist listing for a YouTube User via API

So, here's my code for getting a youtube user's public playlists:

function getyoutubeplaylists($userName) {
$yt = connectyoutube();
$yt->setMajorProtocolVersion(2);
$playlistListFeed = $yt->getPlaylistListFeed($userName);
foreach ($playlistListFeed as $playlistListEntry) {
    $playlist['title'] = $playlistListEntry->title->text;
    $playlist['id'] = $playlistListEntry->getPlaylistID();
    $playlists[] = $playlist;
    $playlistVideoFeed = $yt->getPlaylistVideoFeed($playlistListEntry->getPlaylistVideoFeedUrl());
    foreach ($playlistVideoFeed as $videoEntry) {
        $playlist_assignment['youtube_id'] = substr($videoEntry->getVideoWatchPageUrl(),31,11);
        $playlist_assignment['id'] = $playlist['id'];
        $playlist_assignments[] = $playlist_assignment;
    }
}
$everything['playlists'] = $playlists;
$everything['playlist_assignments'] = $playlist_assignments;
return $everything;
}

Problem is, this only gets the first page or results. Any ideas on how to use the Zend Gdata to retrieve the next page of results?

The raw gdata XML shows the URLs needed:

<link rel="self" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/users/pennstate/playlists?start-index=1&amp;max-results=25"/>
<link rel="next" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/users/pennstate/playlists?start-index=26&amp;max-results=25"/>

However, getPlaylistListFeed doesn't seem to have any parameters to specify "start-index" or "max-results".

like image 590
poolnoodl Avatar asked Oct 11 '22 06:10

poolnoodl


2 Answers

This is a useful Zend function for retrieving not only the next page but all available entries for a feed.

 $playlistListFeed = $yt->retrieveAllEntriesForFeed($yt->getPlaylistListFeed($userName));
like image 113
vaene Avatar answered Oct 12 '22 19:10

vaene


It sounds like you want to follow the Dev Guide example on pagination.

like image 42
mjhm Avatar answered Oct 12 '22 19:10

mjhm