1

Here is a link to the demo: http://davidwalsh.name/xbox-api

I created a php file with the following content..

<?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;
?>    

Here is what its supposed to look like when i load the file (except with my gamertag data)

{
  "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"
  }
}

But it is not displaying anything, what am i doing wrong?

When I go to http://www.xboxleaders.com/api/profile/ryanfabbro.json, it displays fine.

Uodate*

i tryd doing this in a php file

<?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" />

this resulted in the page still being blank so when i viewed the source all it returned was

<img src="" alt="" class="avatar" />

update 2 @ae14 & 2g

i also tried (all in 1 php file)

<?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 ?>

which still resulted in a blank page, is that what you were meaning i should do? i also tried this same way with 2g suggestion to no avail

RyanFabbro
  • 43
  • 1
  • 7
  • 1
    Other than "but it's just blank?", which is a statement - you're telling us that it's blank, rather than asking us - and therefore shouldn't actually have a question mark, you haven't asked a question here at all. – Anthony Grist Oct 30 '12 at 15:48
  • @RyanFabbro - As a warning, please do not insult people commenting on your question. I've removed the offending comment, but please refrain from this in the future. – Brad Larson Oct 31 '12 at 15:47
  • Can you post some HTML code of your page? – 2GDev Oct 31 '12 at 15:57
  • i havent added any html, i have only vreated the php page that has only the top code in it, then it says when you load it it should look like the second set of code – RyanFabbro Nov 01 '12 at 02:24

2 Answers2

3

It looks like you need to use

$user = $json->Data

to get the user information

ae14
  • 401
  • 2
  • 11
  • thanks ae i tried that but it still shows blank, its supposed to grab the xbox data so i can then edit and customize it with css but i cant get the php to display the text – RyanFabbro Oct 31 '12 at 15:31
  • I dont quite understand how the json in your post differs from the link you provide after it. If I hit http://www.xboxleaders.com/api/profile/ryanfabbro.json directly i don't see the user information grouped into the "profile" object. Either way it looks like the variable names you are using in PHP and then inline in your HTML are not matching up. Try using $user = $json->profile in your PHP and then name; ?> in your HTML – ae14 Oct 31 '12 at 16:48
  • Looking a little closer at the Demo page you supplied it looks like the format of the JSON has changed since the tutorial was created. use $user = $json->Data and name ?>. That should work – ae14 Oct 31 '12 at 16:53
  • well i was trying to do that tutorial im pretty new to this, but what i can gather is i should be able to make a php file with just the code i showed on the top, then open that php file and it should look like the code in the bottom, and thats before adding html to it. so i took the line of code $user = $json->user and replaced it with $user = $json->Data and still only showing a blank page – RyanFabbro Nov 01 '12 at 02:19
1

This is my PHP file :

<?php
// Settings

$gamertag = urlencode('yourgamertagwithspaceetcetc..');

$profileUrl = 'http://www.xboxleaders.com/api/profile/'.$gamertag;

// Get information about me
$info = file_get_contents($profileUrl);

echo $info;

// To JSON
$json = json_decode($info);
$user = $json->Data;

echo $user->Gamertag;

?>

I've to use urlEncode beacause my gamertag had a spaces inside. I suggest you to test the final url on the browser before start the php file.

For test use $user->Gamertag because Name's property it's always blank.. I don't know why.

This is JSON Data returned from the service

 "Data": {
    "Tier": "gold",
    "IsValid": 1,
    "IsCheater": 0,
    "IsOnline": 0,
    "OnlineStatus": "Last seen 11\/10\/2012 playing Modern Warfare&#174; 3",
    "XBLLaunchTeam": 0,
    "NXELaunchTeam": 0,
    "KinectLaunchTeam": 0,
    "AvatarTile": "https:\/\/avatar-ssl.xboxlive.com\/avatar\/xxxxxxxx\/avatarpic-l.png",
    "AvatarSmall": "http:\/\/avatar.xboxlive.com\/avatar\/xxxxxx\/avatarpic-s.png",
    "AvatarLarge": "http:\/\/avatar.xboxlive.com\/avatar\/xxxxxx\/avatarpic-l.png",
    "AvatarBody": "http:\/\/avatar.xboxlive.com\/avatar\/xxxxxxx\/avatar-body.png",
    "Gamertag": "xxxxxxxxxxxxxxxxx",
    "GamerScore": 4165,
    "Reputation": 20,
    "Name": "",
    "Motto": "",
    "Location": "",
    "Bio": ""
  },
  "Stat": "ok",
  "In": 2.273,
  "Authed": "false",
  "AuthedAs": null

You can access using the same method for the Gamertag... simpy call

$user->AvatarSmall

I don't had php installed on my machine so first I've downloaded the PHP 5.4.8 for Windows and I've used the Built-in web server of this release Here more info.

Hope can help you

2GDev
  • 2,478
  • 1
  • 20
  • 32
  • so after reading all these posts it looks like i should be adding the echo's in html, do i do this on the php file or a seperate file? could anyone show me an example please – RyanFabbro Nov 01 '12 at 02:26
  • also the link you provided, was not for calling json from a file (already created) or not at least what i saw, so i kinda just got me more confused lol – RyanFabbro Nov 01 '12 at 02:47
  • OMG you rock i kind of gave up hope on this but i finnally came back today and saw your update it works great, now i have to see if i can integrate this into vbulletin, and give it some custom style. THANK YOU SO MUCH! – RyanFabbro Nov 11 '12 at 04:43
  • so would <?php echo $profile->gamertag; ?> be the correct way to call the avatar still? – RyanFabbro Nov 11 '12 at 04:49
  • ahh ill just open a new question about this, since this one is solved THANK YOU AGAIN! – RyanFabbro Nov 11 '12 at 04:52
  • avatar_body doesn't exist on json data returned. See the Edited answer to found all the data returned. Use $user->AvatarBody. – 2GDev Nov 11 '12 at 11:53