How do I get correct OAuth token?

I went to
https://id.twitch.tv/oauth2/authorize?client_id=&redirect_uri=http://localhost&response_type=code

to get my OAuth token, but when I use
function () {
let fetchLink = ‘https://api.twitch.tv/helix/games/top’;

      fetch(fetchLink, {
        method: 'get',
        headers: new Headers({
          'Authorization': 'Bearer <oauth token received>',
          'Client-ID': '<my client id>',
        })
      })
        .then(
          function (response) {
            return response.json();
          }
        )
        .then(
          data => {
            console.log(data);
          }
        )
    }

I get status 401 message saying error: Unauthorized and message: Invalid OAuth token.

How do I get the correct OAuth token?

response_type=code is the first step in “user” oAuth and you redirect the user to that page to authenticate.

You probably in fact need an App Access Token, for server to server requests

NodeJS example of getting a token

Got it working by going to the sample link

GET 'https://id.twitch.tv/oauth2/authorize?response_type=token&client_id=uo6dggojyb8d6soh92zknwmi5ej1q2&redirect_uri=http://localhost&scope=viewing_activity_read

with scope as viewing_activity_read

The OAuth token from this response works. Not sure why adding the scope=viewing_activity_read works but it works for me.

That is the implicit auth response for a client ID that is not yours.

It’s not advised to use the clientID from the documentation.

Please use you own clientID from

I used my own, I just copy and pasted from the documentation for the forum post only. Thanks Barry.

Also worth noting that for public data (such as games/top) you don’t need any scopes.

But if this is a server application, to routinely fetch/update games/top for your own use, you should be using client credentials as the token you have obtained will only work for 60 days or so

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