这是演示的链接:http: //davidwalsh.name/xbox-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;
?>
这是我加载文件时的样子(除了我的玩家代号数据)
{
"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时,它显示得很好。
日期*
我尝试在 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
我也试过(都在 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 建议尝试了同样的方法,但无济于事