OAuth client credentials flow

I’m working on a Python script. I didn’t have too much trouble getting the ‘access_token’ however, my only concern is how often to update and get the new token? I’m reading that I should wait until the token in near expiration, but is their a standard issue on how much time to set? It’s no problem for me to ask for a new token say every 10 minutes, 60 minutes? I just don’t know how twitch determines the amount of time until a token expires?

My initial json shows 4675259 for expiration in milliseconds, but then a second request shows 4809901; what’s the best way to set my recurring token request?

The expires_in field you get given with your access token is in seconds, not milliseconds. App Access Tokens last between 50 and 70 days usually.

Usually there is no need to get a new token until hours, or a day, before it expires.

One option is to check the Validate Token endpoint https://dev.twitch.tv/docs/authentication#validating-requests once a day, and check how much time is left on the token, if it’s less than a day you should get a new one.

Alternatively you can just calculate when the token is set to expire based off of the expires_in when you get the token, and then just regularly compare the current time to the expiration time, and that way you wont need to send a request to the Validate Token endpoint.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.