Getting Twitch channel logo/info when channel is offline

Getting Twitch channel logo/info when channel is offline
0

#1

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){

#3

Thanks for the heads up on both issues.

I’m attempting to get the logo and other info via the channels endpoint but everything is coming back null. This is what I have:

    for(var j = 0; j < streamers.length; j++) {
     $.getJSON('https://wind-bow.glitch.me/twitch-api/channels/' + 
       streamers[i]).done(function(data3){
       console.log(data3);

 });
};

The call comes back with all the attributes null or undefined like this :

Any idea what’s wrong?


#5

That’s a good point and that issue is new to me so thanks for pointing it out, but that wasn’t the problem.

I was looping through the for loop with a variable called j but when I passed the streamers array I passed it with an i, streamers[i]. Wrong variable name.