Type in your question below and we'll check to see what answers we can find...
Loading article...
Submitting...
If you couldn't find any answers in the previous step then we need to post your question in the community and wait for someone to respond. You'll be notified when that happens.
Simply add some detail to your question and refine the title if needed, choose the relevant category, then post.
Before we can post your question we need you to quickly make an account (or sign in if you already have one).
Don't worry - it's quick and painless! Just click below, and once you're logged in we'll bring you right back here and post your question. We'll remember what you've already typed in so you won't have to do it again.
Please see below the most popular frequently asked questions.
Loading article...
Loading faqs...
Please see below the current ongoing issues which are under investigation.
Loading issue...
Loading ongoing issues...
My Question or Issue
I am trying to edit a playlist using the Spotify API and Python. To do this, I first make a request for a new bearer token:
credentials = f"{client_id}:{client_secret}"
encoded_credentials = b64encode(credentials.encode("ascii")).decode("ascii")
headers = {
"Authorization": f"Basic {encoded_credentials}"
}
params = {
"grant_type": "client_credentials",
"scope": "playlist-modify-public user-library-read playlist-modify-private"
}
token_request = requests.post(
url="https://accounts.spotify.com/api/token",
headers=headers,
data=params
)
token = token_request.json()["access_token"]
I then try to use the token to edit a playlist:
auth_header = {'Authorization': f"Bearer {token}"}
formatted_song_uris = ",".join(song_uris)
api_request = f"https://api.spotify.com/v1/playlists/{playlist_id}/tracks?position=0&uris={formatted_song_uris}"
api_call = requests.post(api_request, headers = auth_header)
Which results in the following error:
"error" : {
"status" : 403,
"message" : "This request requires user authentication."
}
When I manually request a bearer token from the Console at developer.spotify.com and use this with Postman and the same url as in the script, it works fine.
Does anyone have any clues as to what is causing the issues? Thanks in advance!
You get this error, because this endpoint requires user authentication.
To let make it work, you'll need to implement the Authorization Code Flow, but I recommend you to use the python module SpotiPy.
Hello,
Thanks for the quick reply.
Does that mean that it is not possible to do it fully automatically, i.e. without any manual user interaction required?
With SpotiPy, you have to log in once. It then stores the tokens in a .cach file. If you run your Python script again, it uses the tokens in that file for authorization.
Note: everytime you change the scopes, the user needs to log in again.
And to answer your question: letting scripts or programs doing things on the behalf if the user, without the user's authorization, would be a big security risk. Also, without logging in, a script or program wouldn't even know on the behalf of wich user it must act.
hey im getting the same error with my JS code , the user access token gets generated successfully but after that when I try to create a playlist with the token the same error pops up .
@lazy3 do you use the Authorization Code Flow?
Getting the same error using postman. I generate the bearer, works with GET calls but when I call a POST or PUT
Are you using a code generated through the Client Credentials Flow or the Authorization Code Flow?
@Ximzend last year I was still able to get a bearer token from the console page at developer.spotify.com and used that token in curl to add tracks to my playlist. Now that console page disappears. Luckily, the bearer token from requests that the spotify web app uses seems to be good enough to add tracks to a playlist. However, the issue is that after a track is added to the playlist with the web api, the playlist doesn't show that track. Do you know what I miss here?
@kfjordt @GustavoParada if you're ok with getting the bearer token manually, you can get it from the developer tools of your browser.
Hey there you, Yeah, you! 😁 Welcome - we're glad you joined the Spotify Community! While you here, let's have a fun game and get…