這裏是演示的鏈接:http://davidwalsh.name/xbox-api的Xbox PHP API調用
我創建了包含以下內容的PHP文件..
<?php
// Settings
$gamertag = 'RyanFabbro';
$profileUrl = 'http://www.xboxleaders.com/api/profile/'.$gamertag.'.json';
// Get information about me
$info = file_get_contents($profileUrl);
// To JSON
$json = json_decode($info);
$user = $json->user;
?>
以下是其應該看起來像當我加載文件(除了我的gamertag數據)
{
"status": {
"is_valid": "yes",
"is_cheater": "no",
"tier": "gold"
},
"profile": {
"gamertag": "dwalsh83",
"gamerscore": 300,
"reputation": 20,
"gender": "male",
"motto": "Watch your head.",
"name": "David Walsh",
"location": "Madison, WI, US",
"bio": "There is, and only can be, Call of Duty.",
"url": "http:\/\/live.xbox.com\/en-US\/Profile?gamertag=dwalsh83",
"avatar_tile": "http:\/\/image.xboxlive.com\/global\/t.fffe07d1\/tile\/0\/2000b",
"avatar_small": "http:\/\/avatar.xboxlive.com\/avatar\/dwalsh83\/avatarpic-s.png",
"avatar_large": "http:\/\/avatar.xboxlive.com\/avatar\/dwalsh83\/avatarpic-l.png",
"avatar_body": "http:\/\/avatar.xboxlive.com\/avatar\/dwalsh83\/avatar-body.png",
"launch_team_xbl": "no",
"launch_team_nxe": "no",
"launch_team_kin": "no"
}
}
但它沒有顯示任何東西,我在做什麼錯?
當我去http://www.xboxleaders.com/api/profile/ryanfabbro.json,它顯示正常。
Uodate *
我tryd在PHP文件
<?php
// Settings
$gamertag = 'RyanFabbro';
$profileUrl = 'http://www.xboxleaders.com/api/profile/'.$gamertag.'.json';
// Get information about me
$info = file_get_contents($profileUrl);
// To JSON
$json = json_decode($info);
$user = $json->user;
$user = $json->profile;
$user = $json->data;
$profile = $json->data;
?>
<img src="<?php echo $profile->avatar_body; ?>" alt="<?php echo $profile->gamertag; ?>" class="avatar" />
這導致頁面仍然是空白的,所以當我看到源做的這一切,它返回是
<img src="" alt="" class="avatar" />
更新2 @ ae14 & 2g
我也嘗試過(所有我n 1 php文件)
<?php
// Settings
$gamertag = 'RyanFabbro';
$profileUrl = 'http://www.xboxleaders.com/api/profile/'.$gamertag.'.json';
// Get information about me
$info = file_get_contents($profileUrl);
// To JSON
$json = json_decode($info);
$user = $json->data;
?>
<?php echo $user->name ?>
這仍然導致一個空白頁,是你應該怎麼做?我也嘗試搭配2G的建議同樣的方式無濟於事
除「但它只是空白的?」,這是一個聲明 - 你告訴我們,它是空白,而不是問我們 - 因此不應該實際上有一個問號,你根本就沒有問過這個問題。 –
@RyanFabbro - 作爲警告,請不要侮辱人們評論你的問題。我已刪除了違規評論,但請在將來避免此事。 –
你可以發佈你的頁面的一些HTML代碼? – 2GDev