Eve-Online API – To use Pheal or just Straight XML – PHP Turtorial

Well hello everyone! Today I am going to talk about a game that I play Eve-Online.  This game is quite nice as it has the ability to allow users who program a option to get in-game information from outside of the game through the use of an API Service.  This API Service gives you information out of the game in the form of XML.  XML is a language that allows for easy modification and manipulation of the data from a external source.  Below i have a output of what the XML looks like when you request the /account/APIKeyInfo.xml.aspx page of the Eve-Online API.  Please note if your going to use the API make sure you have an active account or someone who will give you access to their API key to test things with.

1
2
3
4
5
6
7
8
9
10
11
<eveapi version="2">
  <currentTime>2013-05-15 20:19:27</currentTime>
  <result>
    <key accessMask="134217727" type="Account" expires="">
      <rowset name="characters" key="characterID" columns="characterID,characterName,corporationID,corporationName">
        <row characterID="197034586" characterName="Devilen" corporationID="98180021" corporationName="Worm-Tech Inc."/>
      </rowset>
    </key>
  </result>
  <cachedUntil>2013-05-15 20:24:08</cachedUntil>
</eveapi>

Now that we have this information it is time to decide are we going to use PHP SimpleXML or Pheal.  The difference is Pheal has everything nicely placed for you so that you don’t have to deal with navigating the XML mine field.  Now if you go with SimpleXML you will be able to just directly access the XML that is sent to you and will be forced to handle any and all errors with the XML from CCP (The company that produces and makes Eve-Online).
Example of Pheal:

1
2
3
4
5
6
7
8
9
10
11
12
<?php
  require_once "pheal/Pheal.php";
  spl_autoload_register("Pheal::classload");
 
  $pheal = new Pheal("KeyID", "vCode"); // note you will need to put your own KeyID and vCode in.
 
  $result = $pheal->Characters();
 
  foreach ($result->characters as $characters) {
    echo $character->name."<br>";
  }
?>

What this does will go grab that API Key page using Pheal and it will then take the XML and only grab out for you the Character’s name but only the name so as you can see there are other fields too you can use $character->characterID to get the ID of that Character or $character->corporationName to get the name of the corporation the character is part of or even just grab the information and throw it all into a database to call it back later as this is static information.
Example of SimpleXML:

1
2
3
4
5
6
7
8
<?php
  $apiSite = "https://api.eveonline.com/account/APIKeyInfo.xml.aspx?keyID=&vCode="; // note you will need to put your own KeyID and vCode in.
  $xml = simplexml_load_file($apiSite);
 
  foreach($xml->result->key->rowset->row as $rows){
     echo $rows->attributes()->characterName."<br>";
  }
?>

What is going on is this will go to the site that you put in and grab the output based off the url. This can be a problem if you don’t type in the url correctly or fail to put the correct keyID and vCode in. Then it grabs the XML places it into the place holder of $xml and you then loop the entry of row so it will grab all the characters within the account. You can only have 3 characters per account.

Right now most people will agree when I say that Pheal is simple and less knowledge needed for getting the data out of the xml documents that you have to parse from the Eve Servers. Some might say well the SimpleXML has less lines of code and it looks straight forward. I would agree both are simple and with the exception of Pheal allowing you to change any the URL’s for whats needed by using the $pheal->scope function it is actually a pretty good library. This something you will have to do manually with SimpleXML by editing the URL For the tutorial going forward I will continue to use the Pheal api library and when needed show the SimpleXML counterpart.

If you have anything that you would like to see based off this tutorial let me know and I will see what can be done and if there are any tutorials that I can do for everyone.

Leave a Reply