Twicth API not responding!

Twicth API not responding!
0.0 0

#1

I read through the twitch API documentation and got a Client id as stated on their website but still the API doesn’t seem to respond even when the API is typed i the browser.
Here is the code:
var url="https://api.twitch.tv/kraken/streams/freecodecamp?callback=?";
$.ajax({
type:‘GET’,
dataType:‘jsonp’,
//dataType:jsonp,
url:url,
header:{
‘Client_ID’:“stfuvm4k8xr8o0iv4xzve3p56pt76y”
},
success : function(data){
console.log(data);
}
});
Here is the link to my pen:
https://codepen.io/ryoko1/pen/VWBwea
The main problem that I am facing is that when I type the URL in the browser with the client id I am getting a 400 error


#2

Which url are you typing into the browser? When I tried it I got a correct result:

https://api.twitch.tv/kraken/streams/freecodecamp?client_id=stfuvm4k8xr8o0iv4xzve3p56pt76y


#3

Instead of headers use the pre-request callback function beforeSend.
Also set dataType: 'json' and remove ?callback=? at the end of your url.

$.ajax({
    url: 'https://api.twitch.tv/kraken/streams/freecodecamp',
    type: 'GET',
    dataType: 'json',
    beforeSend: function(xhr) {
                  xhr.setRequestHeader('Client-ID', 'stfuvm4k8xr8o0iv4xzve3p56pt76y');
                },
    success: function(data) {
              console.log(data);
            }
});

try it on jsbin