[GH-ISSUE #240] This requires user authentication #125

Closed
opened 2026-02-27 23:20:57 +03:00 by kerem · 3 comments
Owner

Originally created by @Loewkie on GitHub (Dec 22, 2017).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/240

I'm writing a bit of code which sorts a playlist by the "loudness" value of the tracks, but I;m running into authorization issues. I followed the oauth workflow explained in issue #194 but it doesn't seem to work. Here is the code:

import spotipy
import spotipy.oauth2 as oauth2

credentials = oauth2.SpotifyClientCredentials(
        client_id=CLIENT_ID,
        client_secret=CLIENT_SECRET)

token = credentials.get_access_token()
sp = spotipy.Spotify(auth=token)

playlists = sp.user_playlists('lbevertzen')

for playlist in playlists["items"]:
    if playlist["name"] == "Up to 11":
        to11 = playlist["id"]

tracks = []
for track in sp.user_playlist('lbevertzen',to11)["tracks"]["items"]:
    tracks.append(track["track"]["uri"])

analysis = []
for track in tracks:
    analysis.append(float(sp.audio_analysis(track)["track"]["loudness"]))

sorted_tracks = [x for _,x in sorted(zip(analysis,tracks))]

sp.user_playlist_unfollow('lbevertzen',to11)
sp.user_playlist_create('lbevertzen', 'Up to 11', public=False)

playlists = sp.user_playlists('lbevertzen')

for playlist in playlists["items"]:
    if playlist["name"] == "Up to 11":
        to11 = playlist["uri"]
       
sp.user_playlist_add_tracks('lbevertzen', to11, sorted_tracks)

I end up with the following error:

SpotifyException: https://api.spotify.com/v1/users/lbevertzen/playlists/2PscOEZhD8NM63wrkgPAgh/followers:
 This request requires user authentication.

So obviously something goes wrong during the authentication process, but I don't understand where it all goes wrong.

Originally created by @Loewkie on GitHub (Dec 22, 2017). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/240 I'm writing a bit of code which sorts a playlist by the "loudness" value of the tracks, but I;m running into authorization issues. I followed the oauth workflow explained in issue #194 but it doesn't seem to work. Here is the code: import spotipy import spotipy.oauth2 as oauth2 credentials = oauth2.SpotifyClientCredentials( client_id=CLIENT_ID, client_secret=CLIENT_SECRET) token = credentials.get_access_token() sp = spotipy.Spotify(auth=token) playlists = sp.user_playlists('lbevertzen') for playlist in playlists["items"]: if playlist["name"] == "Up to 11": to11 = playlist["id"] tracks = [] for track in sp.user_playlist('lbevertzen',to11)["tracks"]["items"]: tracks.append(track["track"]["uri"]) analysis = [] for track in tracks: analysis.append(float(sp.audio_analysis(track)["track"]["loudness"])) sorted_tracks = [x for _,x in sorted(zip(analysis,tracks))] sp.user_playlist_unfollow('lbevertzen',to11) sp.user_playlist_create('lbevertzen', 'Up to 11', public=False) playlists = sp.user_playlists('lbevertzen') for playlist in playlists["items"]: if playlist["name"] == "Up to 11": to11 = playlist["uri"] sp.user_playlist_add_tracks('lbevertzen', to11, sorted_tracks) I end up with the following error: SpotifyException: https://api.spotify.com/v1/users/lbevertzen/playlists/2PscOEZhD8NM63wrkgPAgh/followers: This request requires user authentication. So obviously something goes wrong during the authentication process, but I don't understand where it all goes wrong.
kerem closed this issue 2026-02-27 23:20:57 +03:00
Author
Owner

@ritiek commented on GitHub (Dec 22, 2017):

Follow up of #230.

Here you are authorizing using oauth2 method, check out https://github.com/plamere/spotipy/issues/194#issuecomment-317192954:

Note that this method does not need any scope/redirect url and will only allow access to publicly available information.

In your case, you're handling private methods (unfollowing and creating playlist) as well. So this won't work.

You should use the util method (just as you were in #230) to authorize and pass a relevant scope, I haven't tested but a scope of:

scope = 'user-follow-modify playlist-modify-private'

should work.

<!-- gh-comment-id:353618316 --> @ritiek commented on GitHub (Dec 22, 2017): Follow up of #230. Here you are authorizing using `oauth2` method, check out https://github.com/plamere/spotipy/issues/194#issuecomment-317192954: > Note that this method does not need any scope/redirect url and will only allow access to publicly available information. In your case, you're handling private methods (unfollowing and creating playlist) as well. So this won't work. You should use the `util` method (just as you were in #230) to authorize and pass a relevant scope, I haven't tested but a scope of: ``` scope = 'user-follow-modify playlist-modify-private' ``` should work.
Author
Owner

@Loewkie commented on GitHub (Dec 22, 2017):

It's telling me insufficient scope but at least I've finally gotten the authorization process working now. I did in fact forget the scope variable which confused the API. I'll read into the scopes and see what I need to make this work.

<!-- gh-comment-id:353624496 --> @Loewkie commented on GitHub (Dec 22, 2017): It's telling me insufficient scope but at least I've finally gotten the authorization process working now. I did in fact forget the scope variable which confused the API. I'll read into the scopes and see what I need to make this work.
Author
Owner

@sheheryarbutt commented on GitHub (Jan 2, 2018):

I am having a similar issue but with creating a playlist, I tried what you guys said, it got rid of user authentication error but now gives this error on #242 if anyone can check it out and help me, would appreciate it!

<!-- gh-comment-id:354729971 --> @sheheryarbutt commented on GitHub (Jan 2, 2018): I am having a similar issue but with creating a playlist, I tried what you guys said, it got rid of user authentication error but now gives this error on #242 if anyone can check it out and help me, would appreciate it!
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#125
No description provided.