# Live checker - Am I going about this the right way?

**URL:** <https://discuss.dev.twitch.com/t/live-checker-am-i-going-about-this-the-right-way/7389>\
**Category:** API\
**Created:** [September 15, 2016, 12:58am UTC](https://discuss.dev.twitch.com/t/live-checker-am-i-going-about-this-the-right-way/7389 "2016-09-15T00:58:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![TZionic](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/tzionic/32/2028_2.png) [@TZionic](https://discuss.dev.twitch.com/u/TZionic)\
**Post date:** [September 15, 2016, 12:58am UTC](https://discuss.dev.twitch.com/t/live-checker-am-i-going-about-this-the-right-way/7389/1 "2016-09-15T00:58:27Z")

</div>

Hi there. First, I’ll explain how I’m checking a channel’s live status and then I’ll describe the problem that I’m running into.

I query the API every 60 seconds. The url that I use is “[https://api.twitch.tv/kraken/streams?channel=](https://api.twitch.tv/kraken/streams?channel=)” + the channel name. Then, if the “\_total” value found there is greater than 0, the channel is live, otherwise it is offline.

This works fine until the streamer goes offline. The first check shows offline like it should, then the second mistakenly shows online, and the third and every one after that accurately shows offline until the streamer actually starts streaming again. Currently, I’m working around this by only taking the status as being accurate if the checks show the same status twice in a row.

Is there a different URL and element within the response that I should be using? Of course, the error could be with my code. So, if the consensus is that my method is sound, then I will just continue to investigate my code and see if I can find the fault. Thanks for reading.

-TZ

---

<div class="post-metadata">

**Author:** ![Dist](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dist/32/7192_2.png) [@Dist](https://discuss.dev.twitch.com/u/Dist)\
**Post date:** [September 15, 2016, 1:40am UTC](https://discuss.dev.twitch.com/t/live-checker-am-i-going-about-this-the-right-way/7389/2 "2016-09-15T01:40:15Z")

</div>

Try using “[https://api.twitch.tv/kraken/streams/test\_channel](https://api.twitch.tv/kraken/streams/test_channel)”, if a stream is offline then the ‘stream’ value is simply null, otherwise it is the stream object.

---

<div class="post-metadata">

**Author:** ![tduva](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/tduva/32/392_2.png) [@tduva](https://discuss.dev.twitch.com/u/tduva)\
**Post date:** [September 15, 2016, 12:14pm UTC](https://discuss.dev.twitch.com/t/live-checker-am-i-going-about-this-the-right-way/7389/3 "2016-09-15T12:14:26Z")

</div>

This could be caching in the Twitch API, where you hit different servers (I assume) and get different results until all the cache is updated. At least in my experience it’s not too unusual to sometimes get different results (back and forth time-wise) when doing several close together requests. I haven’t paid attention to it recently though.

It’s always good to examine your code of course.

---

<div class="post-metadata">

**Author:** ![DallasNChains](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dallasnchains/32/1608_2.png) [@DallasNChains](https://discuss.dev.twitch.com/u/DallasNChains)\
**Post date:** [September 15, 2016, 2:29pm UTC](https://discuss.dev.twitch.com/t/live-checker-am-i-going-about-this-the-right-way/7389/4 "2016-09-15T14:29:20Z")

</div>

@tduva is right. Our caching on the API is anywhere between 1 - 3 minutes. We cache and load balance endpoints aggressively for scaling reasons.

---

<div class="post-metadata">

**Author:** ![Qntm](https://avatars.discourse-cdn.com/v4/letter/q/5fc32e/32.png) [@Qntm](https://discuss.dev.twitch.com/u/Qntm)\
**Post date:** [September 19, 2016, 8:16am UTC](https://discuss.dev.twitch.com/t/live-checker-am-i-going-about-this-the-right-way/7389/5 "2016-09-19T08:16:48Z")

</div>

@TZionic If you have the ability to keep a daemon process running, you should check out the [PubSub system](https://github.com/justintv/Twitch-API/tree/master/PubSub) for live notifications about the stream status. You wouldn’t have to poll the API and get the notification pretty much instantly. `video-playback` topics are documented in [this PR](https://github.com/justintv/Twitch-API/pull/583).

---

<div class="post-metadata">

**Author:** ![DallasNChains](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dallasnchains/32/1608_2.png) [@DallasNChains](https://discuss.dev.twitch.com/u/DallasNChains)\
**Post date:** [September 19, 2016, 3:59pm UTC](https://discuss.dev.twitch.com/t/live-checker-am-i-going-about-this-the-right-way/7389/6 "2016-09-19T15:59:52Z")

</div>

@TZionic and @Qntm Fair warning about the video-playback topics. The video-playback topics aren’t meant for third party use. They can be removed or changed at any time, so you’re taking on that risk if your application relies on it.

---

<div class="post-metadata">

**Author:** ![Qntm](https://avatars.discourse-cdn.com/v4/letter/q/5fc32e/32.png) [@Qntm](https://discuss.dev.twitch.com/u/Qntm)\
**Post date:** [September 19, 2016, 5:00pm UTC](https://discuss.dev.twitch.com/t/live-checker-am-i-going-about-this-the-right-way/7389/7 "2016-09-19T17:00:07Z")

</div>

Oh, really? I was expecting those to get official, since there is already a pending PR. I guess that’s the reason it hasn’t been merged yet?

---

<div class="post-metadata">

**Author:** ![DallasNChains](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dallasnchains/32/1608_2.png) [@DallasNChains](https://discuss.dev.twitch.com/u/DallasNChains)\
**Post date:** [September 19, 2016, 6:13pm UTC](https://discuss.dev.twitch.com/t/live-checker-am-i-going-about-this-the-right-way/7389/8 "2016-09-19T18:13:42Z")

</div>

That’s correct. That pending PR is from a community member.

---

<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:** [October 19, 2016, 6:13pm UTC](https://discuss.dev.twitch.com/t/live-checker-am-i-going-about-this-the-right-way/7389/9 "2016-10-19T18:13:44Z")

</div>

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