How to show Twitch streaming status and viewer count using Helix API

So, Ive been getting more and more into doing live streams with my friends and followers.
I’m also making a game that I wanted it to show when I was actively streaming so hopefully they could chime in my chat. I made this super bare bones function so it will show if you are actively live streaming.

You are welcome to use it. Once I am complete with my GUI with this included I will post an update.

So how it works:
I’m using Twitch’s new Helix API to login as myself along with their improved developer Applications

Lets get right into it!
To create an Application.

  1. Name it whatever you feel like.
  2. Under your redirect URL, put in your main https://twitch.tv/YOURCHANNEL.
  3. Category: Game Integration
  4. Create it.
    Now go back and manage said application you just created and put it in the variable I have listed as key

I made the variables self-explanatory, client id, and client secret; however, to get the client secret you need to do the human check then click “New Secret”, from there you will have a small dialog box giving you the code. DO NOT GIVE YOUR CLIENT SECRET OUT!

Furthermore, you’ll want to put your channel name under the variable ch_name

Run this as a server-sided script with HttpService on.

image

Also a note
Since Twitch’s helix api resets is cache every ~5 minutes or so. You need to be streaming for at least 6 minutes for this function to pick it up! (Or be very lucky and have you stream update right before their caching servers clear)

Heres a picture of the public key and where it should be.


UPDATED FROM INITAL POSTING!!!

Since the initial posting Twitch has updated their OAuth / Helix API back in April 2021; thus I have been working on an updated module which you will be seeing here. Module linked down below.
Twitch Helix API 2.3.rbxm (4.3 KB)

I have an example of what you want your module / script to look like; very basic simple things with this new module as I want everyone to be able to use it

You are more than welcome to message me on Discord with any questions, comments, or concerns.
12GaugeNick#9116 You can also find my on the official ROBLOX Discord / DevForum Discord.

25 Likes

Hey, thanks for this. However I am getting a 401 status code back, I did everything you did. Am I doing something wrong or did something change?

3 Likes

Mine seems to be working, however double check your key. It may be sending something weird.

2 Likes

I cannot get any help with this from ANYONE on twitch so im gonna say it here. When making an application im stuck in an endless loop of having to do the re captcha and then when i click “create” it resets and I get the error of not doing the captcha which starts the loop.

I would reset all cookies and cache first off. It sounds like a cookie might have gotten hung up somewhere

Hi I need help with this, can you please walk me through it? I don’t exactly know Twitch, I am new to it. I also don’t know where to put the script, can you please help? :slight_smile:

I’m receiving the same 401 error that OutlookG was getting. Could something have changed?

probably because you’re not authorized to access the asset

Sorry to bump :grimacing:

Wanting to know what the best way of getting it updated at a decent rate is. Since it just returns a function , I assume this would fire once when a server is started and that’s it. But what happens if I go live after the servers already been created??

I know you say here that it updates every 5 minutes

But I don’t see how that does with the code given.

At the moment, I do

while true do
    local Live, Details = TwitchCheck() -- return function

    wait(6 * 60)
end

(note, I added a true/false statement to the start of the returns, to basically tell if live or not)

Is that I’m supposed to be doing, or will this cause rate or request limits to be reached??

@NinjoOnline No problem at all, the OAuth at that time only needed acceptance once even if you aren’t streaming and then start streaming. It was a bit funky back then as Twitch had recently added the new API. However…

Now OAuth just needs to run a single time and it replies a code for the HTTP header. No need to update the function anymore; in fact, I have a whole new module ready and presented in this article.

I highly recommend you check the module out now as it’s far more efficient with many new things added to it.

Sorry for such a late reply. Work has me busy. I highly recommend you message me on Discord for quicker responses.

One of the biggest issues I’ve been facing with making this API is that Twitch is such a rapidly growing platform for bots / external things is that there’s always something new being added to their API.