Skip to content
Advertisement

How to use pagination with alaouy/youtube laravel package?

I’m using alaouy/youtube package for one of my projects, Its working just fine, But with this method I can’t use pagination! Is there any way or I’ve to write my own code? There is a vendor folder in my resources with pagination folder but I can’t get work with it!

// List videos in a given channel, return an array of PHP objects
$videoList = Youtube::listChannelVideos('UCk1SpWNzOs4MYmr0uICEntg', 40);

Advertisement

Answer

I’m the creator of that package, happy that it was helpful for you and sorry that the documentation wasn’t clear enough. The listChannelVideos is based on the searchAdvanced method, so you can paginate the channel videos like this :

$params = array(
    'channelId'     => 'UCk1SpWNzOs4MYmr0uICEntg',
    'type'          => 'video',
    'part'          => 'id, snippet',
    'maxResults'    => 40);

// Make intial call. with second argument to reveal page info such as page tokens
$search = Youtube::searchAdvanced($params, true);

print_r($search); // First page results

// Check if we have a pageToken
if (isset($search['info']['nextPageToken'])) {
    $params['pageToken'] = $search['info']['nextPageToken'];
}
// Make another call and repeat
$search = Youtube::searchAdvanced($params, true);

print_r($search); // Second page results

Hope this will help you!

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement