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&max-results=25"/>
<link rel="next" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/users/pennstate/playlists?start-index=26&max-results=25"/>
However, getPlaylistListFeed doesn't seem to have any parameters to specify "start-index" or "max-results".
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));
It sounds like you want to follow the Dev Guide example on pagination.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With