Last active
December 4, 2020 07:17
-
-
Save nikoheikkila/8686164 to your computer and use it in GitHub Desktop.
PHP: Check from Twitch.tv APIv3 if channel is live
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Use Twitch.tv API v3 to check if the specified channel has stream going on | |
* | |
* @author Niko Heikkilä, 2014 | |
* @param STRING $channel Representing the channel/account name | |
* @return BOOL TRUE if online, FALSE if offline | |
*/ | |
function is_channel_live( $channel ) | |
{ | |
$request = json_decode( @file_get_contents( 'https://api.twitch.tv/kraken/streams/' . $channel ) ); | |
return ( ! is_null( $request->stream ) ) ? TRUE : FALSE; | |
} | |
?> |
@SrJoosh and @shadowcoinx:
Yep, I'd modify this script to be checked via AJAX (it just needs to echo
back something useful for XHR request) and then add the desired elements with Javascript (or jQuery, if that's your thing) to the page's HTML. There could be a interval/repeat function or a refresh button that would launch the request.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! How i can add e.g image if channel is online and another image if channel is offline?
And just to clarify will i replace $channel with channel name