Currently working on the Twitch.tv project and having a bit of problem with displaying the code.
Here is my code:
$(document).ready(function() {
var users = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"];
for (i=0; i<users.length; i++) {
var url="https://api.twitch.tv/kraken/channels/" + users[i];
var logo;
var channel;
var status;
$.ajax ({
type: 'GET',
url: url,
headers: {
'Client-ID': 'hw8qejm816w6tjk88fdhfjz1wxpypm'
},
success: function(data) {
logo = data.logo;
channel = data.name;
}
});
var url2 = "https://api.twitch.tv/kraken/streams/" + users[i];
$.ajax ({
type: 'GET',
url: url2,
headers: {
'Client-ID': 'hw8qejm816w6tjk88fdhfjz1wxpypm'
},
success: function(data2) {
if (data2.stream == null) {
status = "Offline";
} else {
status = "Online";
};
}
});
$("#channelInfo").prepend("<div class='row'><div class='col-xs-4'><img src="+logo+"></div><div class='col-xs-4'>"+channel+"</div><div class='col-xs-4'>"+status+"</div></div>")
};
});
I am sure the API is working well. I make 2 API calls here, one to “https://api.twitch.tv/kraken/channels/” and another to “https://api.twitch.tv/kraken/streams/”, because I would like to display the channel logo even when a channel is offline, and the /streams/ calls doesn’t display this information in the json when the stream is offline (or ‘null’).
Rest of my code can be found here: http://codepen.io/drhectapus/pen/VPNQJa