Diablo® III

Simple API Data Retrieval

There are 2 URL's that provide Character Data:
http://us.battle.net/api/d3/profile/KrullCat-1863/
http://us.battle.net/api/d3/profile/KrullCat-1863/hero/228916

The first returns basic data and the second above returns a
comprehensive listing.

The following code blocks populate PHP arrays with flat text data
relative to the characters information:

Array created ($HeroBase)

$strjson = file_get_contents('http://us.battle.net/api/d3/profile/KrullCat-1863/');
//print_r($arrjson);
$HeroBase = json_decode($strjson, true);
// Test
if(is_array($HeroBase)) {
//echo '<pre>';
//print_r($HeroBase);
//echo '</pre>';
}


Array Created ($Ext) Short for 'Extended' information.

$strjson = file_get_contents('http://us.battle.net/api/d3/profile/KrullCat-1863/hero/228916');
//print_r($arrjson);
$Ext = json_decode($strjson, true);
// Test
if(is_array($Ext)) {
//echo '<pre>';
//print_r($Ext);
//echo '</pre>';
}


In the code blocks above you can simply remove the slashes between the IF
statement conditional and the code block will show the list of variables contained
in the Array retrieved from the Diablo Server.

If you wish to see your servers PHP configuration use this small script on it's own:

<?php
// Show all PHP config information
phpinfo();
?>


The arrays are typically multidimensional meaning that if you wish to assign a
value to a particular variable or access a particular value you must use the array
call for that particular value ie:

This block from the ($HeroBase) array contains 2 levels - [heroes]['paragonLevel']

"heroes" : [ {
"paragonLevel" : 25,
"name" : "KrullCat",
"id" : 228916,
"level" : 70,
"hardcore" : false,
"gender" : 0,
"dead" : false,
"class" : "barbarian",
"last-updated" : 1398039781
} ],

If I wanted to assign my Paragon Level and name values from the array to two
individual Variables I would call in the value like so:

$ParaLevel = $HeroBase[heroes]['paragonLevel'];
$CharName = $HeroBase[heroes]['name'];


This particular code would assign the value of (name) in the array to the variable
$CharName
and likewise it would assign the (paragonLevel) value to the variable $ParaLevel
in my PHP code.

I could then use the values stored in those variables for anything within my code.

The list of values in the Extended array or ($Ext) is very long and detailed you will
have to go through and find the values you want and assign or use them as you
wish. Character stats are located close to the very bottom of the Extended array.
The second code block listed above.

Not all servers run or operate with the same PHP code so be sure to run the small
program above with the small phpinfo() code block in order to determine what PHP
specifics your server is running.

I hope this information is valuable for those looking for a direct way of accessing the API's
information.
Edited by KrullCat#1863 on 4/23/2014 10:37 AM PDT
Reply Quote
Here is the complete code block for retrieving and showing the array with my
characters information, simply change the values with your own character values
in the URL call at the top of the script to get your own character data.

<?PHP
$strjson = file_get_contents('http://us.battle.net/api/d3/profile/KrullCat-1863/hero/228916');
//print_r($arrjson);
$Ext = json_decode($strjson, true);
if(is_array($Ext)) {
echo '<pre>';
print_r($Ext);
echo '</pre>';
}
?>


Drop this into a text file and rename it with an extension of (.php) then
upload it to your server and call it from your browser.
Reply Quote
yes, I did it and working fine.

Now I need to put on my website: paragon lvl and elite kills. How do make link to file with this?
Reply Quote
What advantage does this have over a Json parser?
Reply Quote

Please report any Code of Conduct violations, including:

Threats of violence. We take these seriously and will alert the proper authorities.

Posts containing personal information about other players. This includes physical addresses, e-mail addresses, phone numbers, and inappropriate photos and/or videos.

Harassing or discriminatory language. This will not be tolerated.

Forums Code of Conduct

Report Post # written by

Reason
Explain (256 characters max)
Submit Cancel

Reported!

[Close]