Client ID and OAuth token do not match

Hello!
I’m just trying to learn how API works and can’t actually connect it :frowning:

 const fetch = require("node-fetch");

// Use fetch() to make the request to the API
const url = "https://api.twitch.tv/helix/search/channels?query=a_seagull";

const options = {
  headers: {
    'Client-ID': '50pypihh5uaz12rzk10y9v83vra8co',
    'Authorization': 'Bearer wyxhmro***9fz1cr76p7'
  }
};

fetch(url, options)
  .then( res => res.json() )
  .then( data => console.log(data) );

It says {error: ‘Unauthorized’, status: 401, message: ‘Client ID and OAuth token do not match’}

The Client ID and OAuth token do not match error is usually because you didn’t generate your own token, so just to check is that Client ID you’re using yours, and is the OAuth token generated from one of the authorization flows by that app?

Yes, I think so

That’s not a valid OAuth redirect URL

You need to follow the authentication docs https://dev.twitch.tv/docs/authentication
The Redirect URL is where the user will be sent after going through your OAuth flow. Once you’ve obtained an OAuth token from that auth process you can the use it to make API requests.

1 Like

Thanks for answering but I’m stuck again
So… Basically I need to just modify this thing ? And now if I paste

  const url = "https://api.twitch.tv/helix/search/channels?query=a_seagull";

    const options = {
      headers: {
        'client-id': TWITCH_CLIENT_ID,
        'Authorization': 'Bearer ' + accessToken
      }
    };

    fetch(url, options)
      .then( res => res.json() )
      .then( data => console.log(data) );

this code right after github’s one it says “accessToken is not defined”…
I guess I’m just not smart enough :frowning:

This suggest that you didn’t define the access token.

If your intent is to only obtain public data.

Then you should set your redirect URI to http://localhost/.

Then generate a server to server / client credentials token

Documentation: Getting OAuth Access Tokens | Twitch Developers

NodeJS Example: https://github.com/BarryCarlyon/twitch_misc/tree/master/authentication/app_access_tokens/nodejs

Then you can pass in the access token from your generator to your channel search function you have pasted

Just make sure you are doing this all on the backend, not the frontend, as frontend will leak your client secret and generated token(s)

This example is for User Authentication, and you wouldn’t be using user authentication (or passportJS) for the purpose of just checking public data.

So depends what you end goal is here.

1 Like

Thanks everyone for answering! But the problem was that I was trying to do everything but not trying to find my bearer accesstoken. And found it randomly in online generator. I’m really sorry for your time :cry:
P.S. I guess I missunderstanding your answers just because English is not my main :frowning:

Yeah you shouldn’t be using a random online generator.

As you then have to jump hoops to get the correct client-ID

The generator is good for random tests.
But it’s better to use your own authentication loops and not someone elses generator

1 Like

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