[GH-ISSUE #440] get_user_saved_tracks returning empty json #257

Closed
opened 2026-02-27 23:21:39 +03:00 by kerem · 10 comments
Owner

Originally created by @zapell on GitHub (Feb 13, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/440

I am trying to get my spotify data using Spotipy but when i run:

token = util.prompt_for_user_token(username, scope="user-library-read user-top-read", client_id=client_id, client_secret=client_secret, redirect_uri='http://localhost/')
sp = spotipy.Spotify(auth=token)

and then

tracks = sp.current_user_saved_tracks()

it returns empty json data.
The only time it work is when I do
top.current_user_top_artists(limit=10, time_range='long_term')
but not with a different parameter value for time range.

Originally created by @zapell on GitHub (Feb 13, 2020). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/440 I am trying to get my spotify data using Spotipy but when i run: ``` token = util.prompt_for_user_token(username, scope="user-library-read user-top-read", client_id=client_id, client_secret=client_secret, redirect_uri='http://localhost/') sp = spotipy.Spotify(auth=token) ``` and then ``` tracks = sp.current_user_saved_tracks() ``` it returns empty json data. The only time it work is when I do ```top.current_user_top_artists(limit=10, time_range='long_term')``` but not with a different parameter value for time range.
kerem closed this issue 2026-02-27 23:21:39 +03:00
Author
Owner

@ritiek commented on GitHub (Feb 13, 2020):

Do you get the same behaviour when you try out the web API from https://developer.spotify.com/console/get-current-user-saved-tracks/ ?

<!-- gh-comment-id:585660808 --> @ritiek commented on GitHub (Feb 13, 2020): Do you get the same behaviour when you try out the web API from https://developer.spotify.com/console/get-current-user-saved-tracks/ ?
Author
Owner

@zapell commented on GitHub (Feb 13, 2020):

Thanks for the response! yea, I ran
curl -X "GET" "https://api.spotify.com/v1/e/tracks?limit=10&offset=0" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer <TOKEN>"

(with my token in place )
It returns this:
{
"href" : "https://api.spotify.com/v1/me/tracks?offset=0&limit=10",
"items" : [ ],
"limit" : 10,
"next" : null,
"offset" : 0,
"previous" : null,
"total" : 0

I was rerunning this code from a couple months ago, where I had no trouble with this issue, so I am unsure of why it arose.

<!-- gh-comment-id:585838433 --> @zapell commented on GitHub (Feb 13, 2020): Thanks for the response! yea, I ran `curl -X "GET" "https://api.spotify.com/v1/e/tracks?limit=10&offset=0" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer <TOKEN>"` (with my token in place <TOKEN>) It returns this: { "href" : "https://api.spotify.com/v1/me/tracks?offset=0&limit=10", "items" : [ ], "limit" : 10, "next" : null, "offset" : 0, "previous" : null, "total" : 0 I was rerunning this code from a couple months ago, where I had no trouble with this issue, so I am unsure of why it arose.
Author
Owner

@ritiek commented on GitHub (Feb 14, 2020):

tracks = sp.current_user_saved_tracks()

returns all tracks under "Favourite Songs" for the current user. You probably have not saved any tracks to your Favourite Songs, so it's returning empty.

Are you trying to fetch all tracks that the user has saved in all their playlists?

<!-- gh-comment-id:586202876 --> @ritiek commented on GitHub (Feb 14, 2020): ```python tracks = sp.current_user_saved_tracks() ``` returns all tracks under "Favourite Songs" for the current user. You probably have not saved any tracks to your Favourite Songs, so it's returning empty. Are you trying to fetch all tracks that the user has saved in all their playlists?
Author
Owner

@zapell commented on GitHub (Feb 14, 2020):

Yes that is what I am trying to do. I ran this a couple months ago and it was returning my saved songs. I am trying to get all of my liked/saved tracks.

<!-- gh-comment-id:586357000 --> @zapell commented on GitHub (Feb 14, 2020): Yes that is what I am trying to do. I ran this a couple months ago and it was returning my saved songs. I am trying to get all of my liked/saved tracks.
Author
Owner

@ritiek commented on GitHub (Feb 14, 2020):

I don't see why it wouldn't work for you. It seems to good for me.

I have these 4 tracks favourited as in this screenshot:
favsongs

and I can fetch them using spotipy with:

import spotipy
import spotipy.util as util

token = util.prompt_for_user_token(
        username=USERNAME,
        scope='user-library-read user-top-read',
        client_id=CLIENT_ID,
        client_secret=CLIENT_SECRET,
        redirect_uri=REDIRECT_URI)

sp = spotipy.Spotify(auth=token)

tracks = sp.current_user_saved_tracks()
for item in tracks["items"]:
    print(item["track"]["name"])

And the output is:

War of Change
Fallin
Sign
Curtain Call

Is something like this what you're trying to do?

<!-- gh-comment-id:586375603 --> @ritiek commented on GitHub (Feb 14, 2020): I don't see why it wouldn't work for you. It seems to good for me. I have these 4 tracks favourited as in this screenshot: ![favsongs](https://user-images.githubusercontent.com/20314742/74550967-56d9b700-4f78-11ea-8228-8267469c4cb6.png) and I can fetch them using spotipy with: ```python import spotipy import spotipy.util as util token = util.prompt_for_user_token( username=USERNAME, scope='user-library-read user-top-read', client_id=CLIENT_ID, client_secret=CLIENT_SECRET, redirect_uri=REDIRECT_URI) sp = spotipy.Spotify(auth=token) tracks = sp.current_user_saved_tracks() for item in tracks["items"]: print(item["track"]["name"]) ``` And the output is: ``` War of Change Fallin Sign Curtain Call ``` Is something like this what you're trying to do?
Author
Owner

@zapell commented on GitHub (Feb 14, 2020):

Yea i just tried that code and it did not work for me. I'm wondering if I have my spotify app settings screwed up? I have the redirect url set to "http://localhost/"

<!-- gh-comment-id:586383016 --> @zapell commented on GitHub (Feb 14, 2020): Yea i just tried that code and it did not work for me. I'm wondering if I have my spotify app settings screwed up? I have the redirect url set to "http://localhost/"
Author
Owner

@zapell commented on GitHub (Feb 14, 2020):

It's strange because when I do this I get all of my playlists returned.

playlists = sp.user_playlists(USERNAME) for playlist in playlists['items']: print("Name: {}, Number of songs: {}, Playlist ID: {} ". format(playlist['name'].encode('utf8'), playlist['tracks']['total'], playlist['id']))

<!-- gh-comment-id:586385823 --> @zapell commented on GitHub (Feb 14, 2020): It's strange because when I do this I get all of my playlists returned. `playlists = sp.user_playlists(USERNAME) for playlist in playlists['items']: print("Name: {}, Number of songs: {}, Playlist ID: {} ". format(playlist['name'].encode('utf8'), playlist['tracks']['total'], playlist['id']))`
Author
Owner

@ritiek commented on GitHub (Feb 14, 2020):

That's really weird.

I have the redirect url set to "http://localhost/"

I don't think that should be a problem. If other API methods work fine for you, then current_user_saved_tracks should work too.

You should probably open an issue on Spotify's web-api repo and put a link to this issue in the description. Given that curl fails too https://github.com/plamere/spotipy/issues/440#issuecomment-585838433, this likely has something do with Spotify's side with get-current-user-saved-tracks method not working as expected.

<!-- gh-comment-id:586388186 --> @ritiek commented on GitHub (Feb 14, 2020): That's really weird. > I have the redirect url set to "http://localhost/" I don't think that should be a problem. If other API methods work fine for you, then `current_user_saved_tracks` should work too. You should probably open an issue on [Spotify's web-api repo](https://github.com/spotify/web-api) and put a link to this issue in the description. Given that curl fails too https://github.com/plamere/spotipy/issues/440#issuecomment-585838433, this likely has something do with Spotify's side with [`get-current-user-saved-tracks`](https://developer.spotify.com/console/get-current-user-saved-tracks/) method not working as expected.
Author
Owner

@zapell commented on GitHub (Feb 14, 2020):

Ok, I just opened a new issue, thanks for the help

<!-- gh-comment-id:586393003 --> @zapell commented on GitHub (Feb 14, 2020): Ok, I just opened a new issue, thanks for the help
Author
Owner

@stephanebruckert commented on GitHub (Feb 15, 2020):

@zapell since you managed to reproduce the issue with curl I'm going to close this because the problem is not related to python. Please make sure you add all the information needed to understand the issue in https://github.com/spotify/web-api/issues/1473 (without mentioning python).

Also try to double check:

  • that you do have tracks in your "saved songs" on your Spotify account (saved songs and playlists are two different things),
  • that you are using the correct token and not the token of another account.
<!-- gh-comment-id:586589187 --> @stephanebruckert commented on GitHub (Feb 15, 2020): @zapell since you managed to reproduce the issue with curl I'm going to close this because the problem is not related to python. Please make sure you add all the information needed to understand the issue in https://github.com/spotify/web-api/issues/1473 (without mentioning python). Also try to double check: - that you do have tracks in your "saved songs" on your Spotify account (saved songs and playlists are two different things), - that you are using the correct token and not the token of another account.
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/spotipy#257
No description provided.