在有限的共享主机上解析API数据

parsing API data on limited shared hosting

本文关键字:API 数据 主机 共享      更新时间:2023-09-26

建议安装PECL的PHP代码片段 (如果存在,最好坚持使用非PECL PHP选项)

更新:

<?php    
error_reporting(E_ALL);
ini_set("display_errors", "On"); 
$query_params = array( 
    // Specify your developer key 
    'key' => 'XXXXXXX', 
);     
$getdata = http_build_query($query_params);    
$opts = array('http' =>
 array(
    'method'  => 'GET',
    'content' => $getdata
    )
);    
$context  = stream_context_create($opts);    
$response = file_get_contents('http://api.nfldata.apiphany.com/developer/JSON/UpcomingSeason?'.$getdata, false, $context);
?>

通过PHP语法检查器没有得到任何错误;还增加了启用错误的尝试。不知道为什么屏幕是白色的。查看独立开发者URL: http://api.nfldata.apiphany.com/developer/JSON/UpcomingSeason?key=XXXValidDeveloperKey在浏览器内导航时显示"2014"。上面实现了什么都不显示

最近错误:

 Notice: file_get_contents() [function.file-get-contents]: Content-type not specified assuming application/x-www-form-urlencoded in /home/content/69/8610569/html/SFG/nfldata/currentseason.php on line 22

尝试使用本地PHP方法。因此,您提供的代码示例可以转换为如下内容:

<?php     
$query_params = array( 
    // Specify your developer key 
    'key' => '', 
);     
$getdata = http_build_query($query_params);    
$opts = array('http' =>
 array(
    'method'  => 'GET',
    'header' => "Content-Type: application/x-www-form-urlencoded'r'n",
    'content' => $getdata
    )
);    
$context  = stream_context_create($opts);    
$response = file_get_contents('http://api.nfldata.apiphany.com/developer/JSON/UpcomingSeason?'.$getdata, false, $context);
?>

通过PHP语法检查器没有得到任何错误;也添加了尝试在启用错误。我不知道为什么屏幕是白色的。

您没有生成任何输出。插入

echo $response;

?>前面,然后去掉容易出错的?>