jwilsson / spotify-web-api-php

A PHP wrapper for Spotify's Web API.
MIT License
867 stars 156 forks source link

getPlaylistTracks gives the different tracks for playlist generated by user: Spotify when using the API vs using the Spotify sandpit console #246

Closed adamvietnam closed 1 year ago

adamvietnam commented 2 years ago

I have a server-side app that auths using the Client Credential Flow i.e:

$session = new SpotifyWebAPI\Session($this->clientId_,$this->clientSecret_);
$session->requestCredentialsToken();
$this->accessToken_ = $session->getAccessToken();

I then attempt to read a normal user playlist for example:

$uri='spotify:playlist:0inHe5mbRJoHBtPl8dWMYg';
$playlist = $this->spotify_->api()->getPlaylistTracks($uri, ['market' => 'GB','offset' => $offset, 'limit' => $limit]);
print_r($playlist);
die();

I get the expected results i.e. the tracks in the users playlist that I see in the Spotify app.

If I try to do the same with a playlist a smart playlist owned by Spotify for instance "Daily Mix"

$uri='spotify:playlist:37i9dQZF1E395IXQUXa6QW';
$playlist = $this->spotify_->api()->getPlaylistTracks($uri, ['market' => 'GB','offset' => $offset, 'limit' => $limit]);
print_r($playlist);
die();

Again it works as fine and as expected.

If I then try a Playlist owned by Spotify in this case "Lovely Little Playlist"

https://open.spotify.com/playlist/37i9dQZF1DWXRqgorJj26U?si=a4d80532c53844f8

$uri='spotify:playlist:37i9dQZF1DXbZndSu0dHeI';
$playlist = $this->spotify_->api()->getPlaylistTracks($uri, ['market' => 'GB','offset' => $offset, 'limit' => $limit]);
print_r($playlist);
die();

I get a slightly different tracks being returned than I see in the Spotify app. There is a lot of commonality but there are also differences (though interestingly all tracks are the correct style of music.)

If I try this in the Spotify sandpit console (using the OAuth token generated by the console.)

https://developer.spotify.com/console/get-playlist-tracks/?playlist_id=37i9dQZF1DXbZndSu0dHeI&market=&fields=&limit=&offset=&additional_types=

I get the tracks I see in the Spotify app

And if I copy the curl command generated by the sandpit console and run it on my server:

curl -X "GET" "https://api.spotify.com/v1/playlists/37i9dQZF1DXbZndSu0dHeI/tracks?market=GB" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer BQDdrL4L74e_GtbbhDRU0xAYOSV2AMHvntrwacbLdpfBIL9FbMRMJjaoRfSfEdI8kxPqLCtn7AZkHk_HtGjFAC0jOxIgQWlRe-TjNnEoSyinCPa05PaBNUnkXnaCsP7dCOgVQa72aeGw"

It also gives the tracks I see in the Spotify app.

However if I trace down into the Request.php get the Auth token generated by the Client Credentials flow and put into the above curl request i.e.

curl -X "GET" "https://api.spotify.com/v1/playlists/37i9dQZF1DXbZndSu0dHeI/tracks?market=GB" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer BQDwQ8vqob0tLLH2hNbpMru7wqxYXZ_3dbolc0gHBnobpUCPBHSDzaJRWPIXZkuZmOj0WjpeBXssPnB0Ne8"

I get a slightly different set of tracks returned. Again commonality but differences.

NB. Market is set to "GB" in both cases and I have checked is_playable is true or 1 in for all tracks

So my questions would be :

  1. Is there something else I should be specifying to get the same tracks for both spoti-web-api-php vs sandpit console?

  2. Do you think this is to do with the different auth flows or is that a red herring?

3; Do you think this is because "Lovely Little Playlist" is an actually a smart playlist, the tracks being generated dynamically and thus not tightly defined - essentially the behaviour I'm seeing is to be expected.

And finally, If this the right place to ask the question or should I post it on the Spotify dev forums instead.

Many thanks for any insight you can give.

adamvietnam commented 2 years ago

Further another playlist Spotify owned playlist

https://open.spotify.com/playlist/37i9dQZF1EVHGWrwldPRtj

I get totally different results via spoti-web-api-php vs in the Spotify app or Sandbox

jwilsson commented 2 years ago

Hello! This was quite fascinating! I tried requesting the "Lovely Little Playlist" playlist using Client Credentials Flow and Authorization Code Flow with two different accounts. My main account and a test account without any listening history or other data.

Client Credentials Flow and the test account gave the exact same results but with my main account I got totally different results just like you're describing. So I'm thinking the results has to be tied to the authorization flow used. Someone at the Spotify forums might be able to give you more insight though.

adamvietnam commented 2 years ago

Thanks for coming back - glad / sad I wasn't doing something stupid.

I''ll try on the Spotify forums as you suggest, but just to confirm, you could get different results at a curl level i.e. ruling out the PHP API ?

jwilsson commented 2 years ago

Sorry, yes. Using cURL I get the exact same results, one for my main account and a different one for Client Credentials Flow and my test account (but still the same songs as when using this library).

adamvietnam commented 2 years ago

Okay great - glad I can rule out this API.

I'll update here with any info I get from the developer forum just in case someone else runs across the same thing.

dgtyPedro commented 2 years ago

I don't know if it helps, but I already had some problems with the snapshot of the playlists. When I did not passed the snapshot it would return me always the first snapshot of that playlist.

adamvietnam commented 2 years ago

Thanks Pedro, that's interesting.

Can you explain a bit more what you mean by "snapshot" please.

On Thu, 10 Mar 2022 at 00:31, Pedro Caires @.***> wrote:

I don't know if it helps, but I already had some problems with the snapshot of the playlists. When I did not passed the snapshot it would return me always the first snapshot of that playlist.

— Reply to this email directly, view it on GitHub https://github.com/jwilsson/spotify-web-api-php/issues/246#issuecomment-1063520840, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIS7TGEPS5V6XSWROTZXILU7E7F5ANCNFSM5O4QKUCQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>