mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-26 16:15:51 +03:00
[GH-ISSUE #396] Offset field not working for user_playlist_tracks(), wrong response back #234
Labels
No labels
api-bug
bug
dependencies
documentation
duplicate
enhancement
external-ide
headless-mode
implicit-grant-flow
invalid
missing-endpoint
pr-welcome
private-api
pull-request
question
spotipy3
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotipy#234
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @AndrewKassab on GitHub (Oct 10, 2019).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/396
I'm getting an odd issue where I'm not retrieving the response that I'm expecting when calling user_playlist_tracks() to retrieve tracks from a playlist. I still retrieve the songs, but the paging object I receive back is incorrect, which is also preventing the 'limit' and 'offset' field from being set correctly, since they are now located in the 'track' object that gets returned.
According to the spotify docs: https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlists-tracks/
I should be receiving a paging object like such:
Instead, I am receiving this:
Where the
tracksobject contains the paging object that I am actually expecting according to the Spotify docs above.I am aware that this used to work properly since I have previously implemented code to retrieve all the tracks from my playlists, but for some reason, the response I'm getting back now with identical code is different. I'm not sure if this is something that has changed on Spotipy's end or the Spotify API.
@stephanebruckert commented on GitHub (Jan 12, 2020):
Hi, I am correctly receiving something like:
Are you using any fields filter? Closing for now but feel free to re-open with your code.
@stephanebruckert commented on GitHub (Jan 16, 2020):
I just found what happened.
github.com/plamere/spotipy@6da643e8c1/spotipy/client.py (L393)It looks like you've used
user_playlist(notuser_playlist_tracks) withoutplaylist_id. When no playlist id is passed, it used to return your "starred playlist" by default. If that endpoint still responds successfully, most fields are empty because these starred playlists have been removed and have become "liked songs".Anyway, you should now use
playlist(playlist_id)orplaylist_tracks(playlist_id)@AndrewKassab commented on GitHub (Feb 12, 2020):
Still having the same issue. This is my code:
For the given playlist I am testing, response['tracks']['total'] is 699. Every iteration of the while loop is increasing the offset field by another 100, but the offset field never gets set in the playlist_tracks() call. I've followed your advice and used playlist_tracks instead of user_playlist_tracks, but now I just get a response like such.
On one hand I got rid of the irrelevant fields, but on the other hand I still can't get the offset field within the tracks object to get set to anything but 0, and continuously receive the first 100 songs over and over.
Any idea why?? @stephanebruckert
@stephanebruckert commented on GitHub (Feb 12, 2020):
Hey @AndrewKassab. In your code you should have used
itemsinstead oftracks(see doc). I just added an example that usesplaylist_trackshttps://github.com/plamere/spotipy/blob/master/examples/playlist_tracks.py@AndrewKassab commented on GitHub (Feb 12, 2020):
@stephanebruckert
I've followed your advice and made the change, but now all I receive is an empty dictionary / object. I copied your example exactly and received the same response from the playlist_tracks call.
I can't get items because items is inside tracks, and playlist_tracks is returning the parent object containing tracks, and not the tracks object itself....
Is this working on your end? Because I'm very confused. A previous app that I had coded, to use the exact same code to receive all songs from a playlist, stopped working as well with no changes from me and I have no clue why.
@stephanebruckert commented on GitHub (Feb 12, 2020):
Yeah it works for me. For
playlist_tracksthere is no "tracks" field in the response.get-playlist has "items" in "tracks" but get-playlist-tracks only has "items".
@stephanebruckert commented on GitHub (Feb 12, 2020):
So https://github.com/plamere/spotipy/blob/master/examples/playlist_tracks.py does not work for you? What result do you get?
Please also make sure that you are using the latest version:
@AndrewKassab commented on GitHub (Feb 12, 2020):
@stephanebruckert
It does work in your code. Even after the first call to playlist_tracks(playlist_id, fields='items.track.id, total'), when debugging the response is just an empty dictionary.
Could this be a scope or setup issue? Check if you get the chance here
https://github.com/AndrewKassab/Playlist-Sync/blob/master/sync_playlist.py
@AndrewKassab commented on GitHub (Feb 12, 2020):
Just pushed the new code with new fields parameter set
@stephanebruckert commented on GitHub (Feb 12, 2020):
You are still looking for the
tracksfield that does not exist. Please start from the example and adapt it to your needs@AndrewKassab commented on GitHub (Feb 12, 2020):
Sorry. Check now.
@stephanebruckert
@AndrewKassab commented on GitHub (Feb 12, 2020):
When debugging at line 31. Response is empty. Dictionary with length 0
@stephanebruckert commented on GitHub (Feb 12, 2020):
Yeah. As explained in https://github.com/plamere/spotipy/issues/396#issuecomment-585469276,
tracksdoes not exist for the endpoint you are using.github.com/AndrewKassab/Playlist-Sync@b8db8958a2/sync_playlist.py (L31)@AndrewKassab commented on GitHub (Feb 12, 2020):
I'm confused. Like I said I am now calling response = sp.playlist_tracks(playlist_id, fields='items.track.id, total')
And when debugging after this call, response is set to an empty dictionary.
@stephanebruckert commented on GitHub (Feb 12, 2020):
Ok I see,
Your playlist ID here should be
3nWTj1ZAdLJXNiaLdMUOwj@AndrewKassab commented on GitHub (Feb 12, 2020):
@stephanebruckert
nice! You're a legend haha. Thanks a ton
@AndrewKassab commented on GitHub (Feb 12, 2020):
Any explanation as to why it still returned the playlist, but not in the same format?
@stephanebruckert commented on GitHub (Feb 12, 2020):
You mean an empty
{}? Not sure, this has probably more to do with https://github.com/spotify/web-api/. This library is just stupidly returning what Spotify returns@AndrewKassab commented on GitHub (Feb 12, 2020):
I mean when I was calling with fields='tracks', I was receiving an object containing tracks:
Weird, but anyways I can finally say this is solved
@stephanebruckert commented on GitHub (Feb 12, 2020):
Is it possible you were calling
sp.playlist, notsp.playlist_tracks?@AndrewKassab commented on GitHub (Feb 12, 2020):
See here:
Using playlist_tracks on line 28, and debug output below does give me the tracks object
@stephanebruckert commented on GitHub (Feb 13, 2020):
I agree it's a bit weird. Unfortunately I can't test it because
3nWTj1ZAdLJXNiaLdMUOwjmight be private? If you make it public or create a new public one with the same problem, I can check.