This is a FreeCodeCamp project in which I am supposed to show whether or not a channel is live. However, in the list of the channels I’ve created, there are some channels that are live and some channels that doesn’t exist. Still, no matter what, when I tried it test it out in my codepen, it’s still displaying “Offline”, even through some should be displaying “The Account doesn’t exist” or “Online”. I still couldn’t figured it out. I did test the url to make sure it’s working and it’s working. Here’s one example: “https://api.twitch.tv/kraken/streams/OgamingSC2?client_id=egn4k1eja0yterrcuu411n5e329rd3”.
Here’s my JS code:
$(document).ready(function() {
getSteams();
});
var channels = ["BasicallyIDoWrk", "FreeCodeCamp", "Golgothus", "maatukka", "Vinesauce", "brunofin", "comster404", "OgamingSC2"];
var cb = "?client_id=egn4k1eja0yterrcuu411n5e329rd3";
function getSteams() {
for (var channel in channels) {
var indchannel = channel;
$.ajax({
url: "https://api.twitch.tv/kraken/streams/" + indchannel + cb,
type: 'GET',
dataType: "jsonp",
data: {
//action: 'query',
format: 'json',
},
success: function(data) {
var game;
var status;
if(data.stream === null) {
game = "Offline";
status = "offline";
} else if (data.stream === undefined) {
game = "The Account doesn't exist";
status = "Account is closed";
} else {
game = data.stream.game;
status = "online";
};
$("#channels").append('<div class="indbox"><a target="_blank" href="#">'+ game +'</a></div>');
}
});
}
}
Here’s my codepen in action: https://codepen.io/kikibres/pen/EWooLK. I know that it’s not completed. I will finish the rest once I make sure the api is displaying the data correctly.