# Check Online / OffLine

**URL:** <https://discuss.dev.twitch.com/t/check-online-offline/41970>\
**Category:** API\
**Created:** [November 20, 2022, 1:21am UTC](https://discuss.dev.twitch.com/t/check-online-offline/41970 "2022-11-20T01:21:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gazzinet](https://avatars.discourse-cdn.com/v4/letter/g/8797f3/32.png) [@gazzinet](https://discuss.dev.twitch.com/u/gazzinet)\
**Post date:** [November 20, 2022, 1:21am UTC](https://discuss.dev.twitch.com/t/check-online-offline/41970/1 "2022-11-20T01:21:05Z")

</div>

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!!

````auto
<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>```
````

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [November 20, 2022, 1:24am UTC](https://discuss.dev.twitch.com/t/check-online-offline/41970/2 "2022-11-20T01:24:17Z")

</div>

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

> **[twitch\_misc/authentication/app\_access\_tokens/php at main ·...](https://github.com/BarryCarlyon/twitch_misc/tree/main/authentication/app_access_tokens/php)**
>
> main/authentication/app\_access\_tokens/php

Then use the resultant token with the Get Streams API - [Reference | Twitch Developers](https://dev.twitch.tv/docs/api/reference#get-streams) 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.

---

<div class="post-metadata">

**Author:** ![gazzinet](https://avatars.discourse-cdn.com/v4/letter/g/8797f3/32.png) [@gazzinet](https://discuss.dev.twitch.com/u/gazzinet)\
**Post date:** [November 20, 2022, 6:57am UTC](https://discuss.dev.twitch.com/t/check-online-offline/41970/3 "2022-11-20T06:57:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [November 20, 2022, 11:20am UTC](https://discuss.dev.twitch.com/t/check-online-offline/41970/4 "2022-11-20T11:20:41Z")

</div>

> [@gazzinet](#):
>
> but I’ve scrolled through all the bees and I haven’t found any that give me online status

Online status is reported by the get streams API

> **[Reference](https://dev.twitch.tv/docs/api/reference/)**
>
> Twitch Developer tools and services to integrate Twitch into your development or create interactive experience on twitch.tv.

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

---

<div class="post-metadata">

**Author:** ![gazzinet](https://avatars.discourse-cdn.com/v4/letter/g/8797f3/32.png) [@gazzinet](https://discuss.dev.twitch.com/u/gazzinet)\
**Post date:** [November 20, 2022, 8:04pm UTC](https://discuss.dev.twitch.com/t/check-online-offline/41970/5 "2022-11-20T20:04:59Z")

</div>

Thanks @BarryCarlyon 😃

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](https://wiki.gazzi.net/index.php?title=Online/Offline)

Grazie ai suggerimenti di @BarryCarlyon sono riuscito a far le prove per online / offline. Sto creando una guida qui la trovate: [Online/Offline - GazziNet](https://wiki.gazzi.net/index.php?title=Online/Offline)

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [December 20, 2022, 8:05pm UTC](https://discuss.dev.twitch.com/t/check-online-offline/41970/6 "2022-12-20T20:05:50Z")

</div>

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