On live or not -- help

Hi,
I get my stream request and I add my channel in the variable: q=channel.
But I don’t see any information to know if the streaming is on live or whatever information?

my parameters are in an object:

  var FccParam = {
    xav : {
      q:'FreeCodeCamp',
      limit: 30
    }
  };

my request jsonp:

  $.ajax({
    //url: 'https://api.twitch.tv/kraken/streams',
    url: 'https://api.twitch.tv/kraken/streams',
    type: 'POST',
    dataType: 'jsonp',
    data: $.param(FccParam ),
    complete: function (jqXHR, textStatus) {
      console.log(textStatus);
    },
    success: function (data, textStatus, jqXHR) {
      console.log(data );
  });

I think for a not native English like me, it’s worst exercice to do, the explain problem is just doesn’t mean antthing :frowning:

Thanks

If you go with the request like https://api.twitch.tv/kraken/streams/test_channel, your json will have "stream": null if offline and if online will have info about the stream. Examples are here: https://github.com/justintv/Twitch-API/blob/master/v3_resources/streams.md#get-streamschannel
You can get info for multiple channels too (comma separated example on their page). However, as I understand, such requests will not give you damn logos of offline users and you will need to do another request for those pictures (channel one).

You are missing a } after console.log(data );

I’m no expert in jquery, but why don’t you just add channel name to the end of url? Like this:

var FccParam = 'FreeCodeCamp'

$.ajax({
  url: 'https://api.twitch.tv/kraken/streams/' + FccParam,
  type: 'POST',
  dataType: 'jsonp',
  complete: function(jqXHR, textStatus) {
    console.log(textStatus);
  },
  success: function(data, textStatus, jqXHR) {
    console.log(data);
  }
});

I get response:

{
  "stream": null,
  "_links": {
    "self": "https://api.twitch.tv/kraken/streams/FreeCodeCamp",
    "channel": "https://api.twitch.tv/kraken/channels/FreeCodeCamp"
  }
}

That means, that channel “FreeCodeCamp” is not streaming ("stream": null).
Now you can make another ajax call with url from “channel” to get the picture and other info.

Thanks but i don’t have syntax problems, the part of code, here:

  var FccParam = {
    xav : {
      q:'FreeCodeCamp',
      limit: 30
    }
  };

  $.ajax({
    url: 'https://api.twitch.tv/kraken/streams',
    type: 'POST',
    dataType: 'jsonp',
    data: $.param(FccParam ),
    complete: function (jqXHR, textStatus) {
      console.log(textStatus);
    },
    success: function (data, textStatus, jqXHR) {
      console.log(data );

      //url: 'https://api.twitch.tv/kraken/streams',
      for (var j = 0, len = data.streams.length; j < len; j++) {
        var img = (data.streams[j].channel.profile_banner !== null)?data.streams[j].channel.profile_banner :'http://lorempixel.com/50/50';
        $('ul').append(
          '<li class="box__item">'+ 
             '<img class="box__img" src="'+img+'" alt="">'+
             '<a class="box__link" href="'+data.streams[j].channel.url +'" title="" target="_blank">'+
               data.streams[j].channel.display_name+
             '</a>'+
             '<p class="box__descriptioon">'+data.streams[j].game+'</p>'+
          '</li>')
          .addClass('box__item');
      }
    },
    error: function (jqXHR, textStatus, errorThrown) {
      console.log(jqXHR +' : '+textStatus +' : '+errorThrown +' end ');
    }
  });

I have tought time to understand the exercice it self, maybe it’s me, but I’m very disapointed.

I ask in the forum TwichTv and there very clear:

If you’re looking to get a list of people watching the stream, that isn’t something we officially support via the API.

Weirddddd

You don’t have to get list of people watching the stream.

You should take an array of Twitch channels (take these from exercise description ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"]) and show them on the page with info if the channel is streaming or not.

So you take each channel, and call Twitch API for it (you can do it with for loop for example):

let channels = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"]

for (let i = 0; i < channels.length; i++) {

  // make ajax call with url: 'https://api.twitch.tv/kraken/streams/' + channel[i]
  // make ajax call with url: 'https://api.twitch.tv/kraken/channels/' + channel[i]

  // process received channel data and put it on the page
}
2 Likes

If you are not sure what to do, just have a look at the results of others.

I’m feeling like I don’t do it myself, and I have some shame about that, so I did but I want to hide myself.
I’m feeling very bad about it.
Because look the code is to have the solution without personnal work

that’s point for me, to have an array static to call a dynamics links, it’s not somethings we can find in the real life I see now why I fail so bad :frowning: