Reusing the Access Token
After you have fetched an access token you should save it and use it for subsequent calls to the API. There is no limit on the number of calls it can be used for, but it will expire after a certain time.
We recommend that you use the expires_in field to determine when to request a new access token. It specifies the number of seconds the token will be valid for. Because of possible delays in network communication as well as delays between checking the timestamp and transmitting the actual API request, it is a good idea to request a new token a few seconds before it is about to expire. This minimizes the risk of accidentally using an expired token.
The following pseudo code illustrates how to use the authentication endpoint together with the API.
token = get_cached_access_token()
if token == null or is_soon_to_be_expired(token):
token = get_new_access_token()
token = get_token_from_auth_endpoint()
token.expiration_timestamp = now().add_seconds(token.expires_in)
# Add time margin to avoid token expiring during call
if now().add_seconds(60) >= token.expiration_timestamp: