How to pull info about a streamer going online

Hi, I know this is a common issue and answers can be found online, but I couldnt. I am trying to make a chrome extension thats lets people know the stream has started. I know only html/css and bit of php but thats not a problem i guess.
I got this:

curl -H ‘Accept: application/vnd.twitchtv.v2+json’
-X GET https://api.twitch.tv/kraken/streams/test_channel

But i have no idea what to do with it, or what tags to add to make this work in js file.

Hey!

Do you know a bit about JS?
I’ll try to write down the general outline, so you can maybe figure it out yourself.

I’m not sure how this ties into chrome extensions, so I can’t help you with that, but hope this is helpfull.

The API only updates once every 30 seconds or so.
So you’d start with checking for updates every 30 seconds.

Javascript has a setInterval(x,y) function that repeats a given function x every y seconds.

Now, in this loop you probably want to load the channel data, like you did.
You load the data in a variable as a JSON. ( i assume you know this much, if this is too hard, maybe you can use Jquery for this?)

Okay great. We got the data!

Now all you have to do aswell, is check the JSON object called “stream”.
If this isn’t null, the channel is online!
so you can simply compare it to null :smile:

(I think it’s the string “null”)

So now you figured out if the channel is on.

You probably want a variable that keeps check of the last read, so you don’t spam messages about the streamer being online or being offline. so if the new result is different from this global variable, you can show a message.

Hi, thanks for the explanation. I tried to find some examples online, but I couldn’t, most of them cover the json stuff, but my problem is, that I dont really know what to do with the code that loads channel data, or what should be in the js file that loads channel data.

Instead of reinventing the wheel, you could just use a pre-existing solution like TwitchNow.

Making a browser add-on as a new programmer is not an easy task. If you’re persistent on making your own, you’d need to research and learn JavaScript as well as research browser add-on tutorials. You can use Google (or any other search engine) to quickly gain access to material on this subject matter. Asking for help here will likely not get you the support you need, since this is a forum for solving issues integrating with Twitch specifically, not general programming support.

I’ve just got my bot checking the channels it joins every few minutes using the Twitch API json. When it checks, it also checks if and when the channel goes online. When/if it detects the channel online, it then grabs the stream’s current FPS, delay, and a few other statistics.
If you still need something like this, let me know and I can get you the code :slight_smile:

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