Announcements

Help Wizard

Step 1

NEXT STEP

Fetching user's top songs returns error code 500

Solved!

Fetching user's top songs returns error code 500

Hi, I'm all new to the spotify api and this might be just a misunderstanding of mine on how to use the api.

My goal is to sync one of my playlists to 'my top tracks this month' section in my profile which is only visible to me. For that, I've created an application in the spotify dashboard where my personal spotify account is a registered user.

 

To sync the playlist, I've written a little python script that requests an access token (for development purposes with all scopes set) and uses that token to fetch the top 50 monthly songs.

 

Unfortunately, when trying to fetch them, the api returns an error code 500. (You can find the relevant code snippet in the pastebin link below).

 

I can't quite find my error there. What am I missing out here?

 

https://pastebin.com/rNs9Y0DW

 

Thanks in advance

Reply

Accepted Solutions
Marked as solution

Yes, with Spotipy, after you log in, the access token and refresh token will be stored in a .cache file, in the directory where you are running your script from. When the access token expires or run the script again, it uses those tokens automatically, and updates them if needed.

View solution in original post

4 Replies

It's not going to work, because you are trying to use Client Credentials when Authorization is required.

I recommend you to use the Python Spotify API wrapper called SpotiPy to make everything much easier.

Thanks for your answer, that's actually what I implemented while waiting for an answer. But one other question to SpotiPy: Is it possible to "skip" the authorization flow after the first login? My goal is to run this script in the background on my server automated and having to approve the access everytime is not what I'm looking for.

Marked as solution

Yes, with Spotipy, after you log in, the access token and refresh token will be stored in a .cache file, in the directory where you are running your script from. When the access token expires or run the script again, it uses those tokens automatically, and updates them if needed.

Awesome, it's working. Thanks for helping out!

Suggested posts