【发布时间】:2018-09-27 17:32:14
【问题描述】:
我目前正在使用我的 Fortnite 统计数据作为数据创建一个引导网站,并最终将其发布到我的 twitch 提要上。但是,当我在本地计算机上运行时,我设法让它完美地工作,但是当我将它上传到我的 hostgator 目录时,站点加载正常,它只是没有数据。我相信我得到的错误是指我的 JSON 文件,但我假设发生此错误的唯一原因是因为那里没有数据,因为在我的本地机器以外的任何东西上运行时它不能与 Fortnite API 一起使用.有没有其他人曾经经历过这样的事情?
错误:
源映射错误:SyntaxError: JSON.parse: unexpected character at JSON数据的第2行第1列
源地图网址:bootstrap.min.css.map
这是我的代码,我认为发布它没有多大意义,就好像它在我的本地机器上运行逻辑说没问题一样,对吧?
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.fortnitetracker.com/v1/profile/psn/myusername");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'TRN-Api-Key: mykey'
));
$response = curl_exec($ch);
curl_close($ch);
$fp = fopen("stats.json", "w");
fwrite($fp, $response);
fclose($fp);
$data = json_decode(file_get_contents("stats.json"));
$solo = $data->stats->p2;//solos data
$duos = $data->stats->p10;//duos data
$squads = $data->stats->p9;//squads data
$solo_wins = $solo->top1->valueInt;
$duos_wins = $duos->top1->valueInt;
$squads_wins = $squads->top1->valueInt;
$solo_matches = $solo->matches->valueInt;
$duos_matches = $duos->matches->valueInt;
$squads_matches = $squads->matches->valueInt;
$solo_kd = $solo->kd->valueDec;
$duos_kd = $duos->kd->valueDec;
$squads_kd = $squads->kd->valueDec;
$solo_games = $solo->matches->valueInt;
$duos_games = $duos->matches->valueInt;
$squads_games = $squads->matches->valueInt;
$solo_kills = $solo->kills->valueInt;
$duos_kills = $duos->kills->valueInt;
$squads_kills = $squads->kills->valueInt;
?>
【问题讨论】:
-
你有json的副本吗?
-
我同意,但它超过了问题的字符数。但我不认为 JSON 是问题,因为当在我的本地机器上运行时,索引会使用来自 API 的数据生成 JSON 文件。但是当我在我的 HostGator 目录上运行它时,没有生成任何文件。
-
你能把它发布在外部链接上吗,因为 Json 似乎有错误
-
您需要做两件事,在
curl_close之前添加if(curl_error($ch)) { echo 'error:' . curl_error($ch); }还要在curl_exec之前添加curl_setopt($ch, CURLOPT_VERBOSE, 1);。在服务器上运行时出现错误并且您没有打印它。还要添加var_dump($response);以打印您得到的回复 -
正如@TarunLalwani 所说,请打印
curl error并检查Hostgator,可能是您的Hostgator 帐户中没有正确设置cURL。