我正在尝试从 justin.tv 获取视频流信息
我遵循了 wiki 上的代码并遇到了一些错误。在这里输出一些错误后,我得到了。
卷曲:启用
致命错误:Curl 失败并出现错误 #7:无法连接到第 30 行 /srv/disk/14779/www/blah/test.php 中的主机
谁能帮我?我相信我做的一切都是正确的,URL 确实有效,我已经检查过了。
<?php
$streamer = array();
$status = array();
$viewers = array();
$i = 0;
$stream_list = "jojo0123";
echo 'Curl: ', function_exists('curl_version') ? 'Enabled' : 'Disabled';
try{
$mycurl = curl_init();
if (FALSE === $mycurl)
throw new Exception('failed to initialize');
curl_setopt ($mycurl, CURLOPT_HEADER, 0);
curl_setopt ($mycurl, CURLOPT_RETURNTRANSFER, 1);
$url = "http://api.justin.tv/api/stream/list.json?channel=" . $stream_list;
curl_setopt ($mycurl, CURLOPT_URL, "http://api.justin.tv/api/stream/list.json?channel=jojo0123");
$web_response = curl_exec($mycurl);
if (FALSE === $web_response)
throw new Exception(curl_error($mycurl), curl_errno($mycurl));
}
catch(exception $e){
trigger_error(sprintf(
'Curl failed with error #%d: %s',
$e->getCode(), $e->getMessage()),
E_USER_ERROR);
}
echo " web response: " . get_class($web_response) . "\n";
$array = json_decode($web_response);
echo "SIZE OF ARRAY IS " . sizeof($array) . "\n";
foreach($array as $value) {
$streamer[$i] = $value->channel->login;
$viewers[$i] = $value->channel_count;
$status[$i] = "online";
$i++;
}
$data['streams'] = $streamer;
$data['status'] = $status;
$data['viewers'] = $viewers;
echo json_encode($data);
?>