Jump to content
Sign in to follow this  

Youtube Streaming Live Status Button

Recommended Posts

Some of you have already noticed the new, clickable button a the top of the forum showing the Youtube stream's status.


In this thread I'll document how it was implemented if anyone else out there wants to copy it or just learn what I did.


Documentation of how the button was implemented:

1) Enabled the API by registering with Google developers console.


The one you are looking to enable is the "YouTube Data API".

2) Get your Youtube channel ID.


You are going to need it later on.

3) Generate the browser key.

In the Google developers console there, in the same "APIs & auth" section where you enabled the API, there is a subsection "Credentials". Here is where you generate an API browser key. Make a note of it.

You can test the output with this URL (see the two sections where you need to substitute your info?):


4) Query the API.

The youtube live status button works very similarly to the twitch one, JSON decode, but with some changes for extra functionality. Here is the PHP code being used. The button sits in an iFrame at the top of the forum in the same way as the Twitch button.


$json_array = json_decode(file_get_contents("https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=<CHANNEL_ID_GOES_HERE>&eventType=live&type=video&key=<API_KEY_GOES_HERE>"), true);

if ($json_array['pageInfo']['totalResults'] == 0) 
		echo "<a href=https://www.youtube.com/user/tacinept target=newvindow><img src=http://www.tactinept.com/youtubebut/youtube_offline.png></a>";
		echo "<a href=https://www.youtube.com/watch?v=";
		echo $json_array[items][0][id][videoId];
		echo " target=newvindow><img src=http://www.tactinept.com/ytstream/online.gif></a>";

It ain't pretty, just like the twitch code, but it works. The "online" part of the logic statement above is linking directly to the currently live stream, not just to the channel. It's getting the videoID from the API and putting it into the link.


5) Notes


The API is slow. As in, it doesn't appear as "online" or "offline" until almost 5 minutes after you have started/stopped streaming.



Share this post

Link to post
Share on other sites

I'm of the opinion we just kill that button.  We're getting use out of the twitch streaming button.  Last upload to our shared youtube account was me ~3 years ago, so unless we were planning on utilizing the tacinept youtube channel for our various twitch highlights/uploads I don't think even a link is all that useful. 

Share this post

Link to post
Share on other sites

Briefly looked into what might be wrong with it. Something changed with the API but not sure what. Button is just a button now. Does not show live status.

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