Jump to content

API Troubles


AndrewFerrara

Recommended Posts

Can't figure out why this is not working for me... please help! Thanks

 


<?php

$gamertag = 'l RaH l';

$url = "http://api.xboxleaders.com/user_api.php?gamertag=".rawurlencode($gamertag);


$output = file_get_contents($url);

// try to convert the response into a PHP object
$obj = json_decode($output);

if(!is_object($obj)) 
die("Error parsing JSON response\n");

//define variables
$avatar = ($obj->user->avatar);
$gold = ($obj->user->gold);

print $gold;
print $avatar;

?>

Link to comment
Share on other sites

What error are you getting?

 

What is $output equal to?

 

What does the print_r on the $obj look like?

 

When you're debugging, you have to know everything about your program.  You want to know what every little variable is equal to and why it's acting the way it is.  Post on my blog about it here.

Link to comment
Share on other sites

Please somebody actual take a look at this :confused:

 

It like to different parent Arrays i guess, no clue how to access the second one

 

this is what the $output prints:

 




{"error":{"code":200,"desc":"OK"}}{"user":{"gold":1,"gamertag":"l RaH l","avatar":"http:\/\/avatar.xboxlive.com\/avatar\/l%20RaH%20l\/avatarpic-l.png","gamerscore":12508,"reputation":20},"recent_games":[{"recent_game":{"title":"Halo: Reach","link":"http:\/\/gamercard.xbox.com\/en-US\/GameCenter\/Achievements?titleId=1297287259&compareTo=l%20RaH%20l","image":"http:\/\/tiles.xbox.com\/tiles\/ih\/ew\/0Wdsb2JhbA9ECgR8GgMfVlohL2ljb24vMC84MDAwIAAAAAAAAP6fF5U=.jpg"}},{"recent_game":{"title":"Halo 3","link":"http:\/\/gamercard.xbox.com\/en-US\/GameCenter\/Achievements?titleId=1297287142&compareTo=l%20RaH%20l","image":"http:\/\/tiles.xbox.com\/tiles\/Us\/3e\/1Wdsb2JhbA9ECgR8GgMfWSpVL2ljb24vMC84MDAwIAAAAAAAAPrxzU0=.jpg"}},{"recent_game":{"title":"AC Brotherhood","link":"http:\/\/gamercard.xbox.com\/en-US\/GameCenter\/Achievements?titleId=1431504989&compareTo=l%20RaH%20l","image":"http:\/\/tiles.xbox.com\/tiles\/oK\/tp\/1Wdsb2JhbA9ECgUNGgMfVlonL2ljb24vMC84MDAwIAAAAAAAAPpGq78=.jpg"}},{"recent_game":{"title":"Fighters Uncaged","link":"http:\/\/gamercard.xbox.com\/en-US\/GameCenter\/Achievements?titleId=1431504974&compareTo=l%20RaH%20l","image":"http:\/\/tiles.xbox.com\/tiles\/v+\/Au\/0Wdsb2JhbA9ECgUNGgMfVlsmL2ljb24vMC84MDAwIAAAAAAAAP4B4KA=.jpg"}},{"recent_game":{"title":"Assassin's Creed","link":"http:\/\/gamercard.xbox.com\/en-US\/GameCenter\/Achievements?titleId=1431504852&compareTo=l%20RaH%20l","image":"http:\/\/tiles.xbox.com\/tiles\/L3\/mu\/0Wdsb2JhbA9ECgUNGgMfWStXL2ljb24vMC84MDAwIAAAAAAAAP6BeTA=.jpg"}}]}



Link to comment
Share on other sites

I was trying to "actually help."  You can't just post code, say it doesn't work, and expect to get helpful responses back.  We need to know what your code is doing.

 

If you followed the guidelines in that blog post, you could probably figure this out for yourself.

 

That looks like fine output for $output.  What does $obj print out?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.