Twitch TV API problem

Twitch TV API problem
0.0 0

#1

Hi everyone,

I am working on the twitch challenge for 4 days now and I have been stack in one part for the last 3. Particularly, I am getting the “No client id” response error 400 every time I am clicking on a link. 90% of the people who asked for help in this forum was for the same question, but it is very confusing what every person has done and I can’t come up with a solution through other peoples questions. If anyone can take a look on the code and give me a clue where the problem is lying it will be much appreciated!
Thank you!

Here is the code:

 function loadAll(){
channels.forEach(function(channel){

 $.ajax({
    type: 'GET',
    url: test_url+channel+'?client_id='+clientID+'?callback=?',
    headers:{
      'Client-ID': clientID
    }, success: function(data){
    if(data.stream===null && data._links!==null){
      html += "<div class='off'><div class='row' id='containt'><img src='#' id='icon'/><h4 id='text'>"+channel+": <a href='"+data._links.channel+"' id='link_offline'>Offline</a></h4></div></div>";
      $(".channels_collection").html(html);
    } else if(data.status==='404'){
      html += "<div class='off'><div class='row' id='containt'><img src='#' id='icon'/><h4 id='text'>"+channel+": <a href='#' id='link_closed'>Account doesn't exist!</a></h4></div></div>";
      $(".channels_collection").html(html);
    } else {
      html += "<div class='on'><div class='row' id='containt'><img src='"+data.stream.channel.logo+"' id='icon'/><h4 id='text'>"+channel+": <a href='"+data._links.channel+"' id='link_online'>"+data._links.channel+"</a></h4><p id='details'>"+data.stream.game+" - Views: "+data.stream.channel.views+" - Followers: "+data.stream.channel.followers+"</p></div></div>";
      $(".channels_collection").html(html);
    }
    }
    });
  });

}


#2

Hi @DeanDro

I think the problem is that you’re sending the client-id as a query string and in the request header. Try simplifying the url and just sending it in the headers.

url: test_url+channel,
headers:{
  'Client-ID': clientID
}

If that doesn’t work, double check the clientID matches the one you got from the app you registered in the twitch dev connections page. If it’s wrong it will return the same error as if you didn’t supply it.

If that doesn’t work, try sending it as a query string instead, the url should compile to something like:

https://api.twitch.tv/kraken/channels/channelNameHere?client_id=clientIdHere

FYI, when you have more than one value in a query string, you separate them with an &, so: ?client-id=asdas&callback=asds. The callback is unnecessary in this case, just wanted to point it out as you had it slightly wrong in your code.


#3

What I am doing is the follow:

$.ajax({
  url: "https://api.twitch.tv/kraken/channels/" + channel_id,
  headers: {
    "Accept": "application/vnd.twitchtv.v5+json",
    "Client-ID": "xxx"
  },
  success: function(channel_info) {
  }
});

You will need the channel ID in the v5 API which you can get with the following:

 $.ajax({
   url: "https://api.twitch.tv/kraken/users?login=" + channel_name,
    headers: {
      "Accept": "application/vnd.twitchtv.v5+json",
      "Client-ID": "xxx"
    },
    success: function(users_json) {
      if (users_json._total > 0) {
        var channel_id = users_json.users[0]._id;
      }
    }
  });

#4

Thank you guys! It worked by changing the url call and adding the Accept header!