OAuth Problems, probably my own fault anyway :/

A “regular” user token is only valid for four hours.
And you only need to refresh it when you need it.

So you only need to use the refresh token to get a new access token when you are about to go and upload a video, not every 2 hours.

But yes you can use a cronjob to do it every 2 hours.

I have a cronjob that runs every 15 minutes and checks the expiration time on the token

And if it’s less than 30 minutes, then I make a new token. Thats for “high use tokens”

For chat bot tokens I refresh when the bot restarts and needs to connect to chat, since the token only needs to be valid when the bot connects to chat. Then the bot will internally use an app access token to call public data (like stream titles)

This is “industry standard” oAuth. Sure Twitch’s token expiration is potentially shorter than other sites.

But once you have learned oAuth then the exact same code works on a multidue of sites. You just have to plug in a different set of keys and the URL’s

So with a template you can get (off the top of my head)

  • adobesign
  • discord
  • ebay
  • elite dangerous
  • github
  • mixer (yeah it’s dead now)
  • shopify
  • slack

these all use the same base code I jsut feed it different URL’s and lists of scopes

(not Tiwtter that users oAuth 1.0a which works differently)

Whta doesn’t work, what error are you getting for which request?