Twitch API authentication issue: Unauthorized error when fetching top games

Hey folks! I’m trying to get the hang of the Twitch API but I’m hitting a snag. I want to grab the list of top games but it’s not working out.

I got my app access token by sending a POST request to the OAuth endpoint. Then I tried to use that token to fetch the data. I’m using Postman to send a GET request to the games/top endpoint.

But here’s the weird part. I keep getting an ‘Unauthorized’ error saying the OAuth token is missing. I’ve tried it with and without the client ID in the request.

The docs say it should work with either an OAuth token or an app access token. Am I missing something obvious here? Any ideas what could be going wrong?

Here’s a simplified version of what I’m trying:

const fetchTopGames = async () => {
  const response = await fetch('https://api.twitch.tv/helix/games/top', {
    headers: {
      'Authorization': 'Bearer myAccessTokenHere',
      'Client-Id': 'myClientIdHere'
    }
  });
  const result = await response.json();
  console.log(result);
};

Thanks for any help!

I encountered a similar issue when working with the Twitch API. One thing to check is the token scope. Make sure you’ve requested the correct scopes when obtaining your token. For fetching top games, you typically need the ‘analytics:read:games’ scope. Also, verify that you’re sending the token in the correct format in the Authorization header. It should be ‘Bearer [your_token]’ without quotes. If these don’t resolve the issue, try regenerating both your client secret and access token. Sometimes API changes can invalidate older credentials. Hope this helps you troubleshoot!

hey Alex, ran into that issue too! double-check ur token’s still valid - they expire after a while. also make sure ur using the right endpoint (should be helix, not kraken). if that doesn’t help, try generating a new token. let us know if u figure it out!

I’ve dealt with this exact problem before, and it can be frustrating. One thing that often gets overlooked is the Content-Type header. Make sure you’re including ‘Content-Type’: ‘application/json’ in your headers. Also, double-check that your client ID matches the one associated with your access token. Sometimes, if you’ve created multiple apps, it’s easy to mix them up.

Another potential issue could be rate limiting. If you’ve made too many requests in a short time, Twitch might temporarily block your access. Try waiting a few minutes and then attempt the request again.

If none of these solve it, you might want to try using a different HTTP client, just to rule out any issues with Postman. I’ve had success using Axios in Node.js for Twitch API requests. Keep at it, and don’t hesitate to reach out to Twitch support if the problem persists!