[GH-ISSUE #272] Get next page of playlists response #199

Closed
opened 2026-02-27 19:26:34 +03:00 by kerem · 2 comments
Owner

Originally created by @upgrader-dev on GitHub (Mar 5, 2024).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/272

Hello,

I'm trying to get all the playlists of a user with the method getMyPlaylists() of SpotifyWebAPI class with a limit of 20 for example.
My aim is not to load the entire playlist collection to save Spotify server's usage.

So I plan tu use the 'next' property of the response (which is the uri to request to get the next page results).

I'm a beginner here, but as far as I understand, there is no such method to get the next page of playlists, and I can't use the method sendRequest() of SpotifyWebAPI class because it's protected.

If my understanding is correct maybe i could suggest a new method getNextPlaylistsPage($nextUri).

What do you think about that?

Benjamin

Originally created by @upgrader-dev on GitHub (Mar 5, 2024). Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/272 Hello, I'm trying to get all the playlists of a user with the method getMyPlaylists() of SpotifyWebAPI class with a limit of 20 for example. My aim is not to load the entire playlist collection to save Spotify server's usage. So I plan tu use the 'next' property of the response (which is the uri to request to get the next page results). I'm a beginner here, but as far as I understand, there is no such method to get the next page of playlists, and I can't use the method sendRequest() of SpotifyWebAPI class because it's protected. If my understanding is correct maybe i could suggest a new method getNextPlaylistsPage($nextUri). What do you think about that? Benjamin
kerem 2026-02-27 19:26:34 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@jwilsson commented on GitHub (Mar 5, 2024):

Hey Benjamin!
In addition to setting the limit you can also set the offset on subsequent requests to skip the first X number of items.

For example:

$limit = 20;
$offset = 0;
$allPlaylists = [];
$next = '';

do {
  $myPlaylists = $api->getMyPlaylists([
    'limit' => $limit,
    'offset' => $offset,
  ]);

  $allPlaylists[] = $myPlaylists;
  $next = $myPlaylists->next;
  $offset += $limit;
} while ($next != null);

print_r($allPlaylists);

Cheers,
Jonathan

<!-- gh-comment-id:1979202142 --> @jwilsson commented on GitHub (Mar 5, 2024): Hey Benjamin! In addition to setting the `limit` you can also set the `offset` on subsequent requests to skip the first X number of items. For example: ```php $limit = 20; $offset = 0; $allPlaylists = []; $next = ''; do { $myPlaylists = $api->getMyPlaylists([ 'limit' => $limit, 'offset' => $offset, ]); $allPlaylists[] = $myPlaylists; $next = $myPlaylists->next; $offset += $limit; } while ($next != null); print_r($allPlaylists); ``` Cheers, Jonathan
Author
Owner

@upgrader-dev commented on GitHub (Mar 5, 2024):

Ok thank you

<!-- gh-comment-id:1979475925 --> @upgrader-dev commented on GitHub (Mar 5, 2024): Ok thank you
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotify-web-api-php#199
No description provided.