Passing Bearer token does not increase my Ratelimit

Hey Team!

Quick question (as I’m still learning both Ruby & API in general).

I managed to get a Bearer token (my goal was to increase my Ratelimit from 30 to 120). However, I am unable to run more than 30 requests per minute probably because I failed to pass Bearer token properly.

Here’s my snippet (using rest-client gem)

response = RestClient.get "https://api.twitch.tv/helix/streams?first=100",  { 'Client-ID': "#{@client_id}", 'Authorization': "Bearer #{@bearer_token}" }

Then I simply loop through each page using after + cursor value.

Or should I be passing this info directly in the URL?

Have a great weekend!

Seems what you are doing header wise is right.

But seems the Ruby is wrong

GET request with modified headers

RestClient.get ‘http://example.com/resource’, {:Authorization => ‘Bearer cT0febFoD5lxAlNAXHo6g’}

A google suggests your object is wrong? (I’ve not touched ruby in years and years and years so I’m not sure)

1 Like

Hey Barry,

I’m using Ruby 2.5.1 which allows the key: value syntax instead of key => value. Hash Docs for Ruby 2.5.1

But I’ll check anyway to double confirm. Will update this post with an answer. Thanks!

Indeed, as helix doesn’t work at all when no clientID is passed, so that is working…

Yeah. Interesting fact - it literally just started working. And I didn’t do anything ¯_(ツ)_/¯ Oh well, time to fix my loop now. And thanks for the support!

Where do you get Bearer token?

Hey Kein, this is what you’re probably looking for: https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/#oauth-client-credentials-flow

Basically, you need to make a POST request such as this POST https://id.twitch.tv/oauth2/token?client_id=<your_client_id>&client_secret=<your_secret_id>&grant_type=client_credentials

Then you get the answer with your access_token (bearer token):

"access_token": "<user access token>",
  "refresh_token": "",
  "expires_in": <number of seconds until the token expires>,
  "scope": "<your previously listed scope(s)>",
  "token_type": "bearer"

That’s it.

Also, scope is optional. And to refresh your bearer token you simply need to request a new one.

Thanks. Is Bearer-token only valid for limited time? No way to request indefinite version?

Unless you’re a dev with an old app from before token expiration was added, you can’t get an indefinite token, and even then those old tokens will eventually be revoked at some point too.

Just refresh the token a little bit of time before it expires (or in the case of an app access token, just get a new one).

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