Twitch API: It returns undefined and I can't find the solution (SOLVED)

Hello. I am stuck in the “Twitch API” project because when I want to show my channels name, it returns undefined for an unknown reason. Below I will write my code and I will put a link to my codepen.


$(document).ready(function() {
  var streamers = [
    "ESL_SC2",
    "OgamingSC2",
    "cretetion",
    "freecodecamp",
    "storbeck",
    "habathcx",
    "RobotCaleb",
    "noobs2ninjas"
  ];
  var api = "https://wind-bow.glitch.me/twitch-api/";

  for (i = 0; i < streamers.length; i++) {
    var cApi =
      "https://wind-bow.glitch.me/twitch-api/channels/" +
      streamers[i] +
      "?callback=?";
    var sApi =
      "https://wind-bow.glitch.me/twitch-api/streams/" +
      streamers[i] +
      "?callback=?";
      
    $.ajax({
      type: "GET",
      url: cApi,
      datatype: "jsonp",
      jsonp: "callback",
      success: function(result) {
        var name = result.display_name;
        var logo = result.logo;
        console.log(name);
      }
    });
  }
});

https://codepen.io/Terzio/pen/zjPBoq?editors=0001

make the request to the api without the string “?callback=?” .

1 Like

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

markdown_Forums

Hello, I am trying to display who is online and who is offline but I can’t think of a solution.
This is my codePen url:

I will delete this topic once my problem gets fixed. Thanks.

Have to tested to see what you get when you call

https://wind-bow.glitch.me/twitch-api/streams/" + streamers[i]

on a steam that is offline?

Yes. I get null when someone is offline. The problem is that I don’t know how to show in my

  • who is online and who offline.
  • I’ve combined these topics since you’re still asking about the Twitch API.

    1 Like

    well if they are offline you get null so

    if(stream === null){
      // streamer is offline
     // do stuff here
    }else{
      // streamer is online 
    }
    

    Hint #2
    if a stream is offline call
    https://wind-bow.glitch.me/twitch-api/channels/ 1" + streamers[i]
    and see what you get