我的代码突然停止工作,原因不明。我已经手动仔细检查了API响应,看看API的结构是否已经改变但是没有改变。即使启用了error_reporting(E_ALL)
,也不会显示任何错误。
也许你们其中一个人可以弄明白:)
这是我的代码:
<?php
error_reporting(E_ALL);
function hitbox($channel){
$response = json_decode(file_get_contents('http://api.hitbox.tv/media/live/'.strtolower($channel)), true);
$follower = $response['livestream'][0]['channel']['followers'];
$viewer = $response['livestream'][0]['media_views'];
$Game = $response['livestream'][0]['category_name'];
if ($response['livestream'][0]['media_is_live'] == 1) {
echo ("Hitbox: <span class='live'>Live</span><br>");
echo ("Viewers: ".$viewer);
} else {
echo ("Hitbox: <span class='offline'>Offline</span>");
}
}
function twitch($channel){
$response = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams/'.strtolower($channel)), true);
$follower = $response['stream'][0]['channel']['followers'];
$viewer = $response['stream']['viewers'];
if ($response['stream'] !== null) {
echo ("Twitch: <span class='live'>Live</span><br>");
echo ("Viewers: ".$viewer);
} else {
echo ("Twitch: <span class='offline'>Offline</span>");
}
}
?>
以下是我主页中嵌入的响应的实时视图: http://www.kazuto.de/
提前致谢^^