[GH-ISSUE #668] Is there a way to avoid multiple redirects, when you need to use different scopes in the Authorization Code Flow? #395

Closed
opened 2026-02-27 23:22:23 +03:00 by kerem · 4 comments
Owner

Originally created by @leej11 on GitHub (Apr 13, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/668

Hi all,

I'm a new user of spotipy and have just made a draft script to organise my saved tracks into YearMonth playlists.

In my script I'm using the Authorization Code Flow since I need to access user specific information.

The challenge I've encountered is that I end up having to authenticate with the Redirect URLs multiple times. I believe this is because I'm interacting with the API in a few different scopes.

For example the scopes I'm using in the script are:

  • user-library-read scope is used to get my saved tracks
  • playlist-modify-public scope is used to create my playlists
  • playlist-read-private scope is used to read my playlists
  • playlist-modify-public scope is used to add songs to my playlist(s)

Am I misunderstanding something? Is there a way to avoid having to do multiple Redirect URL authentications if the code I'm running needs to query the API with different scopes along the way?

Thanks in advance, really keen to get advice and learn!

Originally created by @leej11 on GitHub (Apr 13, 2021). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/668 Hi all, I'm a new user of `spotipy` and have just made a draft script to [organise my saved tracks into YearMonth playlists](https://github.com/leej11/spotify-organisation/blob/main/main.py). In my script I'm using the [Authorization Code Flow](https://spotipy.readthedocs.io/en/2.17.1/#authorization-code-flow) since I need to access user specific information. The challenge I've encountered is that I end up having to authenticate with the Redirect URLs multiple times. I believe this is because I'm interacting with the API in a few different **scopes**. For example the scopes I'm using in the script are: * `user-library-read` scope is used to get my saved tracks * `playlist-modify-public` scope is used to create my playlists * `playlist-read-private` scope is used to read my playlists * `playlist-modify-public` scope is used to add songs to my playlist(s) Am I misunderstanding something? Is there a way to avoid having to do multiple Redirect URL authentications if the code I'm running needs to query the API with different scopes along the way? Thanks in advance, really keen to get advice and learn!
kerem closed this issue 2026-02-27 23:22:23 +03:00
Author
Owner

@stephanebruckert commented on GitHub (Apr 13, 2021):

You can request multiple scopes by doing:

sp = create_spotipy_authed_instance('user-library-read,playlist-modify-public')

and re-use the same sp everywhere.

In the next version, we will also be able to pass a list as a scope, thanks to https://github.com/plamere/spotipy/pull/650

<!-- gh-comment-id:819030505 --> @stephanebruckert commented on GitHub (Apr 13, 2021): You can request multiple scopes by doing: sp = create_spotipy_authed_instance('user-library-read,playlist-modify-public') and re-use the same `sp` everywhere. In the next version, we will also be able to pass a list as a scope, thanks to https://github.com/plamere/spotipy/pull/650
Author
Owner

@stephanebruckert commented on GitHub (Apr 13, 2021):

@leej11 I just released 2.18.0, so you should be able to pass a list of scopes now

pip3 install spotipy --upgrade
<!-- gh-comment-id:819035624 --> @stephanebruckert commented on GitHub (Apr 13, 2021): @leej11 I just released 2.18.0, so you should be able to pass a list of scopes now pip3 install spotipy --upgrade
Author
Owner

@stephanebruckert commented on GitHub (Apr 15, 2021):

Closing this, let me know if you have any issue with the above answer

<!-- gh-comment-id:820710064 --> @stephanebruckert commented on GitHub (Apr 15, 2021): Closing this, let me know if you have any issue with the above answer
Author
Owner

@leej11 commented on GitHub (Apr 17, 2021):

Hi @stephanebruckert, sorry for my delay in getting back to you, had a busy week 😄 Thanks so much for your response, I've just tried it out using 2.18.0 and supplying a list of scopes, works like a charm!

<!-- gh-comment-id:821843471 --> @leej11 commented on GitHub (Apr 17, 2021): Hi @stephanebruckert, sorry for my delay in getting back to you, had a busy week 😄 Thanks so much for your response, I've just tried it out using `2.18.0` and supplying a list of scopes, works like a charm!
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#395
No description provided.