Last weekend I had a test website working so that when a stream was online the video automatically streamed and if it was offline only text appeared in the spot. Today when I went to work on the site more, it now displays an error despite me not changing anything.
Error: “Warning: file_get_contents(https://api.twitch.tv/kraken/streams.json?channel=sparklyponytv): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home4/sparkly3/public_html/test/wp-content/themes/FreelancerThemeRes/index.php on line 46”
Here is the the basic code I am using which worked last week:
<?php
$streamChannel = "sparklyponytv";
$json_array = json_decode(file_get_contents("https://api.twitch.tv/kraken/streams.json?channel=$streamChannel"), true);
if (isset($json_array['streams'][0]['channel'])) {
echo "<div id='streamonline'>".do_shortcode('[embedTwitch username="sparklyponytv" width="100%"]')."</div></div>";
} else {
echo "<div id='streamoffline'><H3><CENTER><i><font color=#A9A9A9>SparklyPonyTV is currently offline.</font></i></CENTER></H3></div>";
}
?>
Even in it’s simple form (without the shortcode) it gets the same error even though it worked last week!:
<?php
$streamChannel = "your_channel";
$json_array = json_decode(file_get_contents("https://api.twitch.tv/kraken/streams.json?channel=$streamChannel"), true);
if(isset($json_array['streams'][0]['channel'])) {
echo "<div id='streamonline'>embed stuffs here</div>";
} else {
echo "<div id='streamoffline'>offline stuffs</div>";
}
?>