Limit Bearer Token

Im making a Discord Twitch Notification Bot and i want to know if there is a limit of requests with one Bearer Token or not. Cause after x requests i get this reply:{‘error’: ‘Unauthorized’, ‘status’: 401, ‘message’: ‘Invalid OAuth token’}.

A token doesn’t last forever.

So your token may have expired.

You can use the validation API to verify your token and check it’s expirartion time

But its like 10minutes later. I also generated a new one.

If you generate 50 tokens it’ll eat the first token

You might be generating tokens in another script and this first script is holding onto a token that is now dead.

Im doing that like if a token is generated it checks when the token was generated and then if the time is more than x minutes it generates a new token.So that its not to old, but sometimes i get the above error.

This is the wrong approach.

A regular user token last four hours ish
Other tokens last 60 days ish

So you should be generating a token and using it close to when it dies.

This sounds like you keep generating tokens and you have something thats using the first token which is now dead.

I don’t have this problem, so I’m not sure what you could be doing wrong.

My script(s) will generate a token, store it in redis, then everyone will use that token from redis.
And I have a cronjob that will remake that token and put it back into Redis.

So all my scripts should be using the same token.

No im using one token for everything, but im regenerating it

Then I’m not sure whats going on.

Unless you are

And whislt regenning your script is using the old token, but that would only occur if you are revoking or hitting the 50 rule.

So at this point

I’m not sure what the problem could be, something is causing your token to be invalid.

So im making API Requests and if the token that im currently using is older than x minutes or hours, im generating a new one, cause i cant use a token forever or?

For test reasons i generated every 3 minutes a new token and used it, but then an error came

If you call the validate endpoint, it’ll give you the time left (in seconds) on the token.

I usually only generate a new token when there is less than 30 minutes on the token, using a service that runs every 15 minutes

Your message here:

Suggests you are regenerating more often

So your token should be good.
I’m not sure what is breaking where in your workflow.

This suggests that it broke after 150 minutes and your script is using token 1, rather than the new generated token

i think that my script isnt using the old one, i will check it now and tell you

what means the ish after 60 days?

Client Credential Tokens generally last about 60 days, but not exactly 60 days

So they last 60 days ish

I just checked and my token regenerates.
So i can just make that the token regenerates every 50 days and it´ll work?
Is it also okay if i just regenerate the token for every single api request, i dont think so?

Thats bad practice and may cause problems such as the exact problem you are having in this thread, since you are spam generating tokens.

You should, generate, store, recall and reuse a token till it’s close to expirartion

Well sort of, when you generate a token it gives you the expires_in so you know when it expires, and the validate endpoint gives you the time left on the token so you can test how long is left on a token.

I wouldn’t hard code it at 50 days since the expiration time could change

So my problem is cause im spamming generating them? So if i just generate them the time i get in the request for that token, it should work?
sorry for my bad english btw.

I don’t know. Possibly


I’ve listed the common causes of what you describe based on what you have written.