Receiving 401 (Unauthorized)

Hello guys, I’m new to this and I’m just trying to fetch some data using the API, but I keep receiving error 401. My Client-ID is correct, I don’t know what else it could be. Can you guys see if there is something wrong with my code?

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
function GetGame(){
    var result = [];
    
    $.ajax({
      type: 'GET',
      url: 'https://api.twitch.tv/helix/streams?game_id=33214',
      headers: {
        "Client-ID" : "MY_ID_HERE",
        "Accept": "application/vnd.twitchtv.v5+json"
      },
      success: function(json) {
        result.push(json.streams);
        console.log(json);
        console.log(result);
    }});

    return result;
}

GetGame();
</script>

Are you obtaining and using an oAuth token?

  • You don’t need the v5 header with helix
  • You don’t have an oAuth token, Helix requires an oAuth token

I’m following step 2 from this doc https://dev.twitch.tv/docs/api it does not mention an oAuth token. Where should I find about this?:

You missed the header at the top.

Some of the documentation has not been updated to account for the recent changes to the API

My bad, Thanks for pointing it out!

No problem!

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