Check Online / OffLine

With the previous version of the API I used this code to put a warning on my site that I was online. Now I can’t figure out how to use the new version I haven’t found anything that gives me back online/offline. Help!!

<html>
<head>
<title>Title</title>
<script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
</head>
<body>

<h1>My First Heading</h1>
<p>My first paragraph.</p>

<p id="display"></p>

<script>
$.getJSON('https://api.twitch.tv/kraken/streams/gazzinet?client_id=9qkgzqx87m7gp56epvcii07mw8c6oi', function(channel) {

if (channel["stream"] == null) { 
    document.getElementById("display").innerHTML = "NOT LIVE";

} else {
    document.getElementById("display").innerHTML = "LIVE";

}
});
</script>

</body>
</html>```

The API requires a token now.

So you would use server side code to generate an App Access Token.
And use that to perform lookups on the API

Alternatively if using server side you can eventsub and collect live status into a database, and Twitch will tell you when a stream starts or ends.

You cannot and should not generate an app access token in the front end as that would leak what is essentially a password, and I don’t think you want to use an implicit auth as you don’t want to be having random website visitors login to generate a token to use.

So in summary, you need some server side code.

Something like this would be suitable if you have access to PHP

Then use the resultant token with the Get Streams API - Reference | Twitch Developers and collect the result

Store the stream status result into a database or a file and then load that into your front end display.

For a website with random visitors that you don’t want to nudge for them to login with Twitch with, you need some server side code.

In the meantime, thanks, but I’ve scrolled through all the bees and I haven’t found any that give me online status. Today I’m preparing the server part and about everything.

Online status is reported by the get streams API

If the requested user is not live then you get no data, if the stream is live then you get data.

Thanks @BarryCarlyon :smiley:

Thanks to suggestions from @BarryCarlyon I was able to test for online / offline. I’m creating a guide here you can find it: Online/Offline - GazziNet

Grazie ai suggerimenti di @BarryCarlyon sono riuscito a far le prove per online / offline. Sto creando una guida qui la trovate: Online/Offline - GazziNet

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