I am trying to create an API client, but the problem is that the token changes every hour. I want to create a class that contains a "token" variable that should change every hour.
The idea is to get a token when first run the script, create this object and use it.
I have a function that successfully receives a new token on execution.
class AccessToken:
def __init__(self):
self.token = get_new_access_token()
def new_token(self):
self.token = get_new_access_token()
print(self.token)
while True:
time.sleep(3600)
new_token()
def get_new_access_token():
body = {"client_id": config.ESPORT_ID,
"client_secret": config.ESPORT_SECRET_KEY_API
}
resp = requests.post(f'https://.........../oauth/token', json=body)
return resp