Check if streamer is online

Hello,
I try to migrate my code on new API helix but i’m bad developer. So I try to check if a streamer is online or not

Old code :

var xhr = new XMLHttpRequest();
xhr.open("GET", "https://api.twitch.tv/kraken/streams/STREAMERNAME?client_id=MYCLIENTID", 
true);
var data = JSON.parse(xhr.responseText);
if(data["stream"] == null){
}
else{
var viewers = data["stream"]["viewers"];
var status = data["stream"]["channel"]["status"];
var game = data["stream"]["game"];
}

New code :

var xhr = new XMLHttpRequest();
xhr.open("GET", "https://api.twitch.tv/helix/streams/???", true);
xhr.setRequestHeader("Client-ID", "My client id");
var data = JSON.parse(xhr.responseText);

How can I get stream (null or not), viewers, status, game with the new API ?
I have already check docs !

Thx guys :wink:

Just like the docs say, you can use that endpoint, with either the user_id or user_login querystring param, to get the details of a stream.

If the channel is live you’ll get a stream object in the results, if the channels is offline you’ll get an empty data array.

1 Like

It works perfectly, thank you !

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