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

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=” + 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

Try using “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.

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.

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

@TZionic If you have the ability to keep a daemon process running, you should check out the PubSub system 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.

@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.

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?

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

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