[GH-ISSUE #514] util.prompt_for_user_token() and GUI #309

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

Originally created by @filipfigzalski on GitHub (Jun 16, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/514

Hello,
I'm writing an app controlling spotify playback, which has GUI. Unfortunately util.prompt_for_user_token() is using console to enter URL. I've also tried using automatic authorization process, but for some reason it isn't working.
Is there some other way to authorize user?

Originally created by @filipfigzalski on GitHub (Jun 16, 2020). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/514 Hello, I'm writing an app controlling spotify playback, which has GUI. Unfortunately util.prompt_for_user_token() is using console to enter URL. I've also tried using automatic authorization process, but for some reason it isn't working. Is there some other way to authorize user?
kerem closed this issue 2026-02-27 23:21:55 +03:00
Author
Owner

@IdmFoundInHim commented on GitHub (Jun 19, 2020):

You can use a SpotifyOAuth object.

import webbrowser
from spotipy import SpotifyOAuth

auth = SpotifyOAuth(client_id, client_secret, redirect_uri, scope=scopes)
# If the parameters are set as ENV variables, you can omit them
auth_url = auth.get_authorize_url

try:
    webbrowser.open(auth_url)
    logger.info("Opened %s in your browser", auth_url)
except webbrowser.Error:
    logger.error("Please navigate here: %s", auth_url)

# GUI Input to get response_url

code = auth.parse_response_code(response_url)
auth_token = auth.get_access_token(code, as_dict=False)

Also, if you are making your app available to untrusted clients, be wary about exposing your client secret.

<!-- gh-comment-id:646846442 --> @IdmFoundInHim commented on GitHub (Jun 19, 2020): You can use a `SpotifyOAuth` object. ```py import webbrowser from spotipy import SpotifyOAuth auth = SpotifyOAuth(client_id, client_secret, redirect_uri, scope=scopes) # If the parameters are set as ENV variables, you can omit them auth_url = auth.get_authorize_url try: webbrowser.open(auth_url) logger.info("Opened %s in your browser", auth_url) except webbrowser.Error: logger.error("Please navigate here: %s", auth_url) # GUI Input to get response_url code = auth.parse_response_code(response_url) auth_token = auth.get_access_token(code, as_dict=False) ``` Also, if you are making your app available to untrusted clients, be wary about exposing your client secret.
Author
Owner

@filipfigzalski commented on GitHub (Jun 22, 2020):

Thank you!

Just two minor fixes:

from spotipy import SpotifyOAuth

should be:
from spotipy.oauth2 import SpotifyOAuth

and

auth_token = auth.get_access_token(code, as_dict=False)

was throwing error so I used:
token = auth.get_access_token(code)['access_token']

<!-- gh-comment-id:647682283 --> @filipfigzalski commented on GitHub (Jun 22, 2020): Thank you! Just two minor fixes: > from spotipy import SpotifyOAuth should be: ```from spotipy.oauth2 import SpotifyOAuth``` and > auth_token = auth.get_access_token(code, as_dict=False) was throwing error so I used: ```token = auth.get_access_token(code)['access_token']```
Author
Owner

@IdmFoundInHim commented on GitHub (Jun 22, 2020):

What was the error on the second one? as_dict=True (the default for get_access_token) is deprecated, so it is not reliable.

<!-- gh-comment-id:647689443 --> @IdmFoundInHim commented on GitHub (Jun 22, 2020): What was the error on the second one? `as_dict=True` (the default for `get_access_token`) is deprecated, so it is not reliable.
Author
Owner

@stephanebruckert commented on GitHub (Jun 30, 2020):

This looks solved

<!-- gh-comment-id:651928494 --> @stephanebruckert commented on GitHub (Jun 30, 2020): This looks solved
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#309
No description provided.