0

i want to know how take a value from this json.

i must take the value "FIFA 15" (the field is "name").

The content of the json (http://xboxapi.com/v2/superdeder/xboxonegames) is this:

{ "titles": [ { "lastUnlock": "2014-10-11T12:30:30.4788799Z", "titleId": 122001257, "serviceConfigId": "64c10100-3d40-49d5-8f1c-c99807459769", "titleType": "LiveApp", "platform": "Durango", "name": "YouTube", "earnedAchievements": 3, "currentGamerscore": 0, "maxGamerscore": 0 }, { "lastUnlock": "2014-10-28T21:55:44.6766285Z", "titleId": 1689264723, "serviceConfigId": "0b430100-23ff-43cd-a287-894f64b02253", "titleType": "DGame", "platform": "Durango", "name": "FIFA 15", "earnedAchievements": 11, "currentGamerscore": 350, "maxGamerscore": 1000 } ], "pagingInfo": { "continuationToken": null, "totalRecords": 2 } }

With a normal json i succeed a take the value but with this i believe there is a need of an authentication.

This is the documentation: https://xboxapi.com/documentation.

I use php inside altervista.

thanks!

  • Why you think that you need authentication when the value is in JSON? – Sasa Oct 31 '14 at 10:56
  • because here https://xboxapi.com/documentation, there is the command X-AUTH and the where is the phrase "YOUR_AUTH_KEY_HERE", if i log appears an api key and also in other place... This is another question but with this i haven't problem.. [link](http://stackoverflow.com/questions/26606514/how-can-i-extract-the-value-of-this-json-in-php)[link]. – Andrea Asr Franchi Oct 31 '14 at 11:10
  • Then put your API key there. I don't understand your question... – Sasa Oct 31 '14 at 11:13
  • I do not know how to do it in php to make it work and make me return that value .. – Andrea Asr Franchi Oct 31 '14 at 11:15
  • You can use this library for creating the get or post requests: https://github.com/rmccue/Requests – Sasa Oct 31 '14 at 11:20

1 Answers1

1

You first need to sign in at xboxapi.com with your xbox gametag, or you can create a new gametag specifically for this website. After you have done this you will see your 'XboxAPI API Key' on your profile page on that website, this is your authentication key.

You can now use for example Curl to retrieve the info you want.

$url = 'https://xboxapi.com/v2/superdeder/xboxonegames';
$headers = array('X-AUTH: ***Your API key here***');

$session = curl_init($url); 
curl_setopt($session, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($session, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($session);

curl_close($session);

$myArray = json_decode($response, true);

// You now have the JSON as an array file called $myArray, 
// you can see what's inside the array with:

echo '<pre>';
var_dump($myArray);
echo '</pre>';

//The game FIFA15 is 3rd in your games list, so to retrieve the name you would use:

echo $myArray["titles"][2]["name"];
Sloeser
  • 26
  • 3