Hey guys,
<?php
$url = "https://api.twitch.tv/kraken/streams/greatbritishbg";
$json = file_get_contents($url);
$json = json_decode($json);
var_dump($json);
foreach($json->streams as $stream) {
echo $stream->channel->stream . '<br />';
echo $stream->channel->display_name . ' is playing ' . $stream->channel->game . '.<br />';
echo '<a href="http://www.twitch.tv/' . $stream->channel->name . '">Watch Live</a>';
echo '<hr />';
$status = $stream->channel->stream;
}
//PSUEDO CODE:
if($status == 'Online' {
} else {
}
?>
I'm trying to query whether the cast is online or offline. however I'm getting a foreach error:
Warning: Invalid argument supplied for foreach() in /home2/xtrapsp/public_html/index.php on line 79
Here is a Json dump:
object(stdClass)#1 (2) { ["_links"]=> object(stdClass)#2 (2) { ["self"]=> string(51) "https://api.twitch.tv/kraken/streams/greatbritishbg" ["channel"]=> string(52) "https://api.twitch.tv/kraken/channels/greatbritishbg" } ["stream"]=> NULL }
Thanks in advance guys