[GH-ISSUE #551] Requesting access token with authorization code #332

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

Originally created by @sheptang on GitHub (Jul 29, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/551

I'm aware that get_access_token() is designed to return only the "access_token" value from the general token dictionary.

But unfortunately, some of us would still need to retrieve full dictionary version of the token, by passing the authorization code value.

Because, for my implementation, the dictionary token with all of its other data (such as "refresh_token", "expiry", ...) is needed.

I tried to find any other way to get this data through Spotipy, but the only useful method I found was get_access_token(), and the warning message for as_dict deprecation affects my code flow.

I also tried to work around it, trying to use _request_access_token(), where get_access_token() retrieves its initial data from, but of course, I was unsuccessful since the library wasn't designed like that.

If I'm missing anything or making mistakes, I'm certainly open for feedback or any suggestions. Thanks!

Originally created by @sheptang on GitHub (Jul 29, 2020). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/551 I'm aware that get_access_token() is designed to return only the "access_token" value from the general token dictionary. But unfortunately, some of us would **still need to retrieve full dictionary version of the token, by passing the authorization code** value. Because, for my implementation, the dictionary token with all of its other data (such as "refresh_token", "expiry", ...) is needed. I tried to find any other way to get this data through Spotipy, but the only useful method I found was get_access_token(), **and the warning message for as_dict deprecation affects my code flow**. I also tried to work around it, trying to use **_request_access_token()**, where get_access_token() retrieves its initial data from, but of course, I was unsuccessful since the library wasn't designed like that. If I'm missing anything or making mistakes, I'm certainly open for feedback or any suggestions. Thanks!
kerem 2026-02-27 23:22:03 +03:00
Author
Owner

@stephanebruckert commented on GitHub (Jul 29, 2020):

Try auth_manager.get_cached_token()

<!-- gh-comment-id:665544466 --> @stephanebruckert commented on GitHub (Jul 29, 2020): Try `auth_manager.get_cached_token()`
Author
Owner

@sheptang commented on GitHub (Jul 29, 2020):

Try auth_manager.get_cached_token()

Thanks for lightning fast reply!

I've already tried to use it that way, but the problem is that I need to retrieve the token by passing the auth code in the very beginning of token request. That's why I can't access any cached token before requesting for one.

If I wasn't fairly new to Python, I'd try creating a new method from scratch or a workaround to suit my needs.

<!-- gh-comment-id:665549505 --> @sheptang commented on GitHub (Jul 29, 2020): > Try `auth_manager.get_cached_token()` Thanks for lightning fast reply! I've already tried to use it that way, but the problem is that **I need to retrieve the token by passing the auth code** in the very beginning of token request. That's why I can't access any cached token before requesting for one. If I wasn't fairly new to Python, I'd try creating a new method from scratch or a workaround to suit my needs.
Author
Owner

@stephanebruckert commented on GitHub (Jul 29, 2020):

Have a look at these lines in this example:

github.com/plamere/spotipy@f136442c2d/examples/app.py (L41..L45)

First we use get_access_token(code) without caring about the result, and then you can use token_info = get_cached_token() to retrieve the full json

<!-- gh-comment-id:665551947 --> @stephanebruckert commented on GitHub (Jul 29, 2020): Have a look at these lines in this example: https://github.com/plamere/spotipy/blob/f136442c2d9e579ac78d1e9d4a4f21a231a867aa/examples/app.py#L41..L45 First we use `get_access_token(code)` without caring about the result, and then you can use `token_info = get_cached_token()` to retrieve the full json
Author
Owner

@sheptang commented on GitHub (Jul 29, 2020):

Now it makes perfect sense, looks like I've missed it. My bad.

Thank you!

<!-- gh-comment-id:665554070 --> @sheptang commented on GitHub (Jul 29, 2020): Now it makes perfect sense, looks like I've missed it. My bad. Thank you!
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#332
No description provided.