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

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

#1

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


Twitch Api: I can't show offline and online users
#2

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


#3

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.


#4

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.


#5

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?


#6

You will get more responses if you do not say you will delete the topic after your problem is fixed. If members take the time to respond, the response could help someone else in the similar situation. I like to help as many people as we can when I take the time to respond.


#7

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.

  • #8

    I’ve combined these topics since you’re still asking about the Twitch API.


    #9

    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