Javascript Stream Live Check?!

Hi,

I was using this script:

function CheckOnlineStatus()
{
  $.getJSON("https://api.twitch.tv/kraken/streams/" + channelName, function(channel)
  {
    if (channel["stream"] == null)
    {
      alert(nickname+" is not online");
    } else {
      alert(nickname+" is online!");
    }
  });
}

Now this isn’t working anymore since you need the clientID now.
I registered it and I got my Client ID.
Can you tell me how I can implement the client ID to this script?!

The variables:

  • channelName
  • nickname
    are globals. It’s just the channel name to look for (live or not) and nickname is just a good looking formatted name of this channel.

I made the script short. It have more things in it.
But this should be enough to understand.

Thanks a lot for your help!

EDIT
I use that (a similar script like that) in my chrome extension.
This extension checks every X minutes if a stream is online.
So basically I have to give this script a header with the Client-ID.
IF possible I would not want to use Jquery. But it wouldn’t be a problem at all.
Because my extension already use Jquery. If this script (above) is not working with client id anymore.
Maybe someone can make me a JQuery variant with:

  • alert not online
  • alert online
    So I can use that with my longer script version. Thanks.

Use $.ajax instead to pass the header, or add ?client_id=[your client ID] to the URL.

An example with $.ajax:

function CheckOnlineStatus()
{
  $.ajax({
    url: "https://api.twitch.tv/kraken/streams/" + channelName,
    dataType: 'json',
    headers: {
      'Client-ID': your_client_id
    }
    success: function(channel)
    {
      if (channel["stream"] == null)
      {
        alert(nickname+" is not online");
      } else {
        alert(nickname+" is online!");
      }
    }
  });
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.