Twitch Helix API: Invalid OAuth Token Error

1.9k views Asked by At

I am using the Twitch Helix API and creating an open source Deno module. I have been trying to test out the API, but whenever I send fetch requests, it returns the following:

{
    "error": "Unauthorized",
    "status": 401,
    "message": "Invalid OAuth token"
}

Here is what I am using within my code for the requests:

await fetch(`https://api.twitch.tv/helix/users?login=${login}`, {
  headers: {
    "Client-ID": this.apiData.clientId,
    Authorization: `OAuth ${this.apiData.clientSecret}`,
  },
});

I got my API Client ID and Client Secret from the Twitch Developers Console page for my app. Here are the two keys that I am using:

enter image description here

The code is executed using deno run --allow-net file.ts Do you think that I need to do something else to make sure the request_url is equal to http://localhost for this to be able to work? Also, is it that I need to get a different api key to be able to do this? I also know that my Client ID and Client Secret are correct. I have refreshed them three times already and put the tokens back in and it still doesn't work.

Please help me figure out what I am doing wrong. Thank you very much for your help!

Check out the Twitch Discussion issue for this here!

1

There are 1 answers

0
Jaime Etxebarria On BEST ANSWER

I had the exact same issue a few months ago. The problem is caused by the token and the client-id.

Go to https://twitchtokengenerator.com, select the scopes in the helix part and click generate token. Then use the ACCESS TOKEN and the CLIENT ID that appear in the top part in your code.

That worked for me.