Getting Twitch channel logo/info when channel is offline


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.

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('' + streamers[i] +'?callback=?').done(function(data2) {
    if( != null){
      $('#channelsOnline').prepend("<img src=" + + ">" + "<h3><a href=" + + "</h3><ul><li>" + + " is online now <a/></li><li>followers: " + + "</li><li> viewers: " + + "</li><li> game: " + + "</li>")
    else {
      // Separates name of channel from the rest of the URL
      var channelUrl =;
      var channelName = channelUrl.match(/([^\/]*)\/*$/)[1];

      $('#channelsOffline').prepend("<a href=" + + "><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('' + streamers[i] + 'callback=?').done(function(data3){


You will have to use the /channels/ endpoint to get the logo for offline users. The /streams/ endpoint tells you what someone is streaming (null if offline). The /channels/ endpoint gives you information about the streamer’s channel (or an error if their channel doesn’t exist).

Also, one tip, you won’t need to use JSONP if you use instead of The challenge needs to be updated with the newer server name.


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('' + 


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

Any idea what’s wrong?


I’m guessing at this point that you are hitting a very common problem with running asynchronous code in a for loop. Change your var j = 0 to let j = 0 and it should fix the problem. Ideally, use a forEach to loop through that array of streamers instead. Here’s some background on the issue:


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.


doh! I should have seen that :stuck_out_tongue: glad you got it working!