Jump to content
Sign in to follow this  

Twitch Streaming Live Status Button

Recommended Posts

This is not new content. This is just taken out of the previous thread and moved in here to remain consistent with the youtube streaming thread I just made.


Ok. Just got it working. You should see it now in the top left of the window where there is a graphic that says "Twitch Stream" and then whether it is offline or online. It is a clickable link at all times. The only issue that occurs is that when a stream has just started or ended, for about 30 seconds it flips between offline and online repeatedly. I'm assuming this is something to do with Twitch's API. After 20-30 seconds it levels out and stays correctly online or offline no matter how many times you refresh.


I figured I would catalog how I implemented it for those that might be curious. A little knowledge of html/css/php will probably help....


In the IPB global template (Customization > Themes > TheThemeYouAreEditing > Edit HTML CSS > Templates > Core > Front > Global > Logo) right after this code....

{{if \IPS\Theme::i()->logo['front']['url'] !== null }}
{{$logo = \IPS\File::get( 'core_Theme', \IPS\Theme::i()->logo['front']['url'] )->url;}}
<a href='{setting="base_url"}' id='elLogo' accesskey='1'><img src="{$logo}" alt='{setting="board_name" escape="true"}'></a>

....I put in this code....

<span style="padding-left:70px;"></span>
<iframe src="http://www.tactinept.com/twitchbut/twitch.php" frameborder="0" seamless scrolling="no" height="30" width="100"></iframe>
<iframe src="http://www.tactinept.com/youtubebut/youtube.php" frameborder="0" seamless scrolling="no" height="30" width="100"></iframe>

....and the contents of twitch.php are....


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.twitch.tv/helix/streams?user_login=***CHANNEL* TO*CHECK*HERE***");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Client-ID: ***CLIENT*ID*HERE***"
$profile_data = json_decode(curl_exec($ch), true);

if (!isset($profile_data['data'][0])) {
    echo "<a href=https://www.twitch.tv/tacinept target=newvindow><img src=https://www.tactinept.com/twitchbut/twitch_offline.png></a>";
} else {
    echo "<a href=https://www.twitch.tv/tacinept target=newvindow><img src=https://www.tactinept.com/twitchbut/twitch_online.png></a>";


Initially I didn't want to implement it initially as an iframe but I ran into too many issues trying to use a php include. I also later ran into some issues trying to have the image output of a php function be a clickable link so instead I fell back to an echo command with html links.


You should see some minor graphical changes to it over the next few days/hours but then it should stay.


EDIT: Code updated 6-21-17

EDIT: Code updated 9-19-19

Share this post

Link to post
Share on other sites

This is broken right now and I think I know why.


Twitch blog article from May 5, 2016 - https://blog.twitch.tv/client-id-required-for-kraken-api-calls-afbb8e95f843




Our Kraken API has always had a requirement of including the Client-ID header in order to not be rate limited. We’ve been lenient about this policy thus far and would allow requests without the header. On Monday, August 8th, 2016, we’re going to start requiring the Client-ID header. After the change, any request without the Client-ID header will be rejected.



Looks easy to fix but will take a little time to troubleshoot. It's probably been broken for months but no one has been streaming so it has not really mattered. I will take a look at this when I have a little time.

Share this post

Link to post
Share on other sites

Buttons are working now if you have not noticed. Code in post above has been updated. The reason for the update was (1) the forum update and (2) see my post above on April 5th twitch API changes. Pretty small change but you need a client ID now which means you need to generate one and use it.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...