I’m coming along on the Twitch project and figured out the API calls for the most part, however I’m having a hard time getting the logo from Twitch channels that are currently offline. Here is the codepen. https://codepen.io/nick_kinlen/full/MoxEpZ/
For channels that are currently online I got the logo, followers, etc via the stream object like this:
for(var i = 0; i < streamers.length; i++){
$.getJSON('https://wind-bow.gomix.me/twitch-api/streams/' + streamers[i] +'?callback=?').done(function(data2) {
//console.log(data2);
if(data2.stream != null){
$('#channelsOnline').prepend("<img src=" + data2.stream.channel.logo + ">" + "<h3><a href=" + data2.stream.channel.url + "</h3><ul><li>" + data2.stream.channel.display_name + " is online now <a/></li><li>followers: " + data2.stream.channel.followers + "</li><li> viewers: " + data2.stream.viewers + "</li><li> game: " + data2.stream.channel.game + "</li>")
}
else {
// Separates name of channel from the rest of the URL
var channelUrl = data2._links.channel;
var channelName = channelUrl.match(/([^\/]*)\/*$/)[1];
$('#channelsOffline').prepend("<a href=" + data2._links.channel + "><h3>" + channelName + " is offline" + "</h3>")
}
});
};
That accesses the info and logo via the stream object. When the stream object is null I cannot access the logo property. How would I get the logo if the channel is offline and the stream object is null?
I tried doing it with a getJSON call that looks like this but I get a 403 error, meaning that the call is valid but access is denied.
$.getJSON('https://wind-bow.gomix.me/twitch-api/users?login=' + streamers[i] + 'callback=?').done(function(data3){