Skip to content

Commit

Permalink
Merge pull request #442 from CharleyPearce/master
Browse files Browse the repository at this point in the history
Made cache optional in get_access_token #441
  • Loading branch information
stephanebruckert authored Feb 15, 2020
2 parents 1f1e90e + d71913d commit dcc53b9
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions spotipy/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def get_auth_response(self):
def get_authorization_code(self, response=None):
return self.parse_response_code(response or self.get_auth_response())

def get_access_token(self, code=None, as_dict=True):
def get_access_token(self, code=None, as_dict=True, check_cache=True):
""" Gets the access token for the app given the code
Parameters:
Expand All @@ -349,13 +349,14 @@ def get_access_token(self, code=None, as_dict=True):
stacklevel=2,
)
print("")
token_info = self.get_cached_token()
if token_info is not None:
if is_token_expired(token_info):
token_info = self.refresh_access_token(
token_info["refresh_token"]
)
return token_info if as_dict else token_info["access_token"]
if check_cache:
token_info = self.get_cached_token()
if token_info is not None:
if is_token_expired(token_info):
token_info = self.refresh_access_token(
token_info["refresh_token"]
)
return token_info if as_dict else token_info["access_token"]

payload = {
"redirect_uri": self.redirect_uri,
Expand Down

0 comments on commit dcc53b9

Please sign in to comment.