These forums have been archived and are now read-only.

The new forums are live and can be found at https://forums.eveonline.com/

EVE Technology Lab

 
  • Topic is locked indefinitely.
 

EVE API Tutorial

Author
Trenker
#1 - 2011-10-26 13:09:57 UTC  |  Edited by: CCP Phantom
Since a lot of questions here are very basic, I wrote a little tutorial on how to use the API for a web app using PHP and MySQL

It comes in four parts

  1. Preparations
  2. How to setup your local environment using XAMPP and install the SDD
  3. First API request
  4. Using cURL to fetch data from a public API (CharacterIDs)
  5. Use a library
  6. Request the CharacterSheet using pheal
  7. API and Static Data Dump
  8. Fetch the AssetList and use the SDD to get the names of locations and items.


The whole thing is very low-level for beginners. If you find any errors, please tell me.

# Update 1
Cleared some things up (hopefully!?)
Provide a SDD on site
Use latest Pheal version
Nathan WAKE
Deep Core Mining Inc.
Caldari State
#2 - 2011-10-26 13:13:48 UTC
A very good idea indeed !!

+1

"I'm a very good housekeeper. Each time I get a divorce, I keep the house"

Zaza Gabor

Strangey
Sebiestor Tribe
Minmatar Republic
#3 - 2011-10-26 15:11:32 UTC
Awesome, thanks!
Norian Lonark
Center for Advanced Studies
Gallente Federation
#4 - 2011-10-26 20:45:30 UTC
This is really great thank you very much for putting the effort in to doing this .

Start wide, expand further, and never look back

TorTorden
Tors shibari party
#5 - 2011-10-27 10:51:15 UTC
This should get stickied.

Definetely something those just starting out should read, and those aren't likely to go digging on page 5.
I applaud your initative Trenker :)
Peter Powers
Terrorists of Dimensions
#6 - 2011-10-28 00:10:22 UTC  |  Edited by: Peter Powers
ahoy trenker,

just fastread through it.
i actually think this is a good idea,
but i'd like to mention one thing,
in Part III your usage of pheal is a bit unorthodox.

you implement a singleton kind of way to retrieve an pheal instance,
and pass the key information with every method call.

this should work quite well for what you do in the tutorial,
but you might want to consider using it the usual way, so you can use features like
the accessmask stuff wollari added.

for those not familliar with pheal (i know trenker is)
this means usually you would run something like
Quote:

require_once "Pheal/Pheal.php";
spl_autoload_register("Pheal::classload");

in your bootstraper or config,

and than create an instance with the key parameters.
that way you only have to pass the arguments that are required each call
(which is quite handy if you do several calls).

so trenkers example would look more like.
Quote:

$pheal = new Pheal($keyId, $vCode);
$data = $pheal
->charScope
->CharacterSheet(array('characterID' => $char['characterID']))
->toArray()


this allows you to do call
Quote:
$pheal->detectAccess();

before you call char/CharacterSheet, so pheal will test if the key has the access right, and isvalid,
preventing you from causing errors on the API that can get you banned.

more information on that you find in the Readme on Github

again, its ok to do it the way trenker suggests, if you know what you are doing.
But i'd prefer a tutorial to show the way its meant to be done.

best regards,
PP

Edit:
i just looked at your example, and saw your bundling Pheal 0.0.14, which is outdated -
0.0.14 has no real customizeable key support, so your way of doing it is the only one working.
i'd suggest upgrading to 0.1.0.

customizeable key support has been in pheals developers version (git version) for quite a while,
and was contained in wednesdays release.
(so for all i wrote before, upgrade to pheal 0.1.0 first (you find it at the website mentioned earlier))
i'm sure trenker will update his tutorial soon :)

3rdPartyEve.net - your catalogue for 3rd party applications

Gaitrie
MagmaTech Industries
#7 - 2011-10-28 11:23:10 UTC
This is sooo good - many many tnx for this help

Two questions:

1: how big does the dbase get when you import the dump in to mysql ?
2: movie tutorials next maybe as I am more of a visual person

Mine is Bigger **than **Yours ! <<<

TorTorden
Tors shibari party
#8 - 2011-10-28 12:14:08 UTC  |  Edited by: TorTorden
0.02$

1 :If memory serves the full dump is at around 1.2 GB now, a large part of that is the newer EveLocations and good'ol MapDenormalized.

2: This is scripting, video tutorials would get LOOOOOONG, boring and would need all kinds of complimentery text just to work, as well as making the daunting task of writing howto's 10x times more complex.
Gaitrie
MagmaTech Industries
#9 - 2011-10-28 13:20:12 UTC
uploading the data to a hosting now - taking looooooonngg :-)

Well I thought it would be easier to create do to you speak and show.
well then I need to read it :-).

Mine is Bigger **than **Yours ! <<<

Dragonaire
Here there be Dragons
#10 - 2011-10-28 14:36:58 UTC
One thing I notice in the intro part is telling people to use 'command prompt here' etc which except if you have installed tweakUI or done something else to turn it on isn't available. Most people using XP or later versions of Windows don't even have run available on start menu if they haven't switched to classic menus so you might want to include at least a link to how they can do so or get the other.

Finds camping stations from the inside much easier. Designer of Yapeal for the Eve API. Check out the Yapeal PHP API Library thread.

Trenker
#11 - 2011-10-30 17:36:53 UTC  |  Edited by: Trenker
Peter Powers wrote:
this should work quite well for what you do in the tutorial,
but you might want to consider using it the usual way, so you can use features like
the accessmask stuff wollari added.


The tutorial uses pheal 0.0.14, which does not have those fancy CAK features yet. You released 0.1.0 just a few hours after I wrote that part. I'll update it some time next week, because those are some really nice features. And then we can use a prototype object instead, you're right, that's the better way.

Edit: Just saw your edit. Looks like we are on the same track here.

Gaitrie wrote:
1: how big does the dbase get when you import the dump in to mysql ?
2: movie tutorials next maybe as I am more of a visual person


1: ~ 1.4 GB
2: Neither my voice nor my intonation of the english language are suitable for a video, but if someone else want's to do it, just use the stuff I wrote and make it moving on youtube. Smile

Dragonaire wrote:
One thing I notice in the intro part is telling people to use 'command prompt here' etc which except if you have installed tweakUI or done something else to turn it on isn't available. Most people using XP or later versions of Windows don't even have run available on start menu if they haven't switched to classic menus so you might want to include at least a link to how they can do so or get the other.


I can do it in Win7, Vista and XP. Simply hold the [Shift] key while doing the right click (as I wrote Blink )

Thanks to all for the feedback. Now I feel like doing more.
Zifrian
Federal Defense Union
Gallente Federation
#12 - 2011-11-28 03:17:32 UTC
Nice site. I used your 'find ore and ice' query the other day for EVE IPH development. Smile

The hard part about doing a tutorial for the data dump though is you really need to know and be able to use SQL. Hopefully this will give people the context they need to run their own queries and learn from them.

Any reason to use MySQL over msSQL? Since the datadump is all set for SQLserver, thought it'd be a logical place to start.

Anywho, thanks for the great work!

Maximze your Industry Potential! - Download EVE Isk per Hour!

Import CCP's SDE - EVE SDE Database Builder

Darnoken
State War Academy
Caldari State
#13 - 2011-12-06 22:30:17 UTC
I went through the tutorial, and all I get at the end is an empty drop down menu under the character selector, and the other form for inputting a character name is gone entirely.

I even tried running the completed code given for download at the end, with the same effect...

Am I missing something?
Daneel Trevize
Give my 11percent back
#14 - 2011-12-13 20:32:55 UTC
Peter,

Thanks for your library, here's a few issues I've noticed when trying to use it:

On your github website and in your Readme, your examples with $e->code seem to need to be changed to $e->getCode()

There's a possible typo of 'Date' not 'Data' at the start of the exception message text, e.g.
"generic error: 0 message: API Date could not be read / parsed, original exception: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed "

Lastly and chielfy, I'm getting that SSL error atm, but EVEMon seems to be querying ok.

My code so far is simply the following cobbled from the examples
Quote:
$keyID = "number";
$vCode = "manyletters";

require_once "Pheal/Pheal.php";
spl_autoload_register( "Pheal::classload" );
$pheal = new Pheal( $keyID, $vCode, "char" );
PhealConfig::getInstance()->http_ssl_verifypeer = false;
//PhealConfig::getInstance()->api_base = 'https://api.eveonline.com/';
PhealConfig::getInstance()->http_method = 'curl';
//PhealConfig::getInstance()->http_post = false;
PhealConfig::getInstance()->cache = new PhealFileCache("C:\\Users\\Path\\To\\Pheal\\cache\\");
PhealConfig::getInstance()->access = new PhealCheckAccess();
try {
$result = $pheal->Characters();
foreach( $result->characters as $character ) {
echo $character->name;
}
} catch( PhealAccessException $e ) {
echo "access error: ".$e->getMessage();
/* do something - example: disable key */

} catch( PhealAPIException $e ) {
echo 'api error: ' . $e->getCode() . ' message: ' . $e->getMessage();
/* do something - example: disable key */

} catch( PhealException $e ) {
echo 'generic error: ' . $e->getCode() . ' message: ' . $e->getMessage();
/* do something - example: wait 5 minute next key usage (network/cluster problem) */
}
PHP 5.2.17
libcurl/7.21.0 OpenSSL/0.9.8r zlib/1.2.3
OpenSSL 0.9.8q 2 Dec 2010

I do have a local self-signed SSL cert installed for this Apache instance, could that be an issue?
Nose Snot
Doomheim
#15 - 2012-01-15 14:55:52 UTC
As an uber noob and beginner going through the tutorial, I've come across a lot of missing information.

1. You mention to run the MySql, but never mention to run the Apache service.
2. Took me a while to configure the right-click for "Open command prompt here". Not all systems have this defaulted.
3. and now I'm stuck here...
Quote:
For now we just test if PHP intercepts the formdata. That’s not so much, so let’s build the URL needed to fetch the data by adding this code:

Because you don't mention where to add that code.

Maybe I'm biting off more than I can chew, but if it's a tutorial for experts that know what they are doing already, then they don't need a tutorial. I guess I'll fail on this one.. :(
Trenker
#16 - 2012-02-02 19:31:59 UTC
Darnoken wrote:
I went through the tutorial, and all I get at the end is an empty drop down menu under the character selector, and the other form for inputting a character name is gone entirely.

I even tried running the completed code given for download at the end, with the same effect...


A blank screen or missing part is often a hint on missing error messages, review you PHP settings and error logs

Nose Snot wrote:
1. You mention to run the MySql, but never mention to run the Apache service.
2. Took me a while to configure the right-click for "Open command prompt here". Not all systems have this defaulted.
3. and now I'm stuck here


1. I thought that's obvious, apperantly I was wrong, so added a hint.
2. Removed that line and added a hint on how to get there inside the prompt with the cd command. I'm working on Prof. Editions off Windows since XP, so I always had that shift - right click option !?
3. Cleared that up as well, but please keep in mind that this is no PHP introduction, you have to know how PHP works before starting this tutorial
DuBios
Wolf Investments
#17 - 2012-02-06 13:39:30 UTC
I love this idea, and thank you for doing this tutorial. I have been trying to figure out the eve api thing for a while and since im still pretty newbish on php anyway its been a struggle. Anywho, I went through all this and I got a problem and noticed something. on step 3, I get this message...

Error 0: Cache directory 'C:\xampp\htdocs\eve-charinfo/.pheal-cache/myapiid/myapivcode/account/APIKeyInfo/' isn't writeable

when I get to step 4 it gives me a cant find loadPheal() error message. I reloaded the pages with the completed files in the zip file and get this message...I put that function back into functions.php and get the above Error 0 message again...Help please!
Dunhkan
Doomheim
#18 - 2012-02-27 13:01:48 UTC  |  Edited by: Dunhkan
hi,

First, thank's for your tutorial, it's help me for the basic with api, php and library like pheal.

I have one error when i press "display selected characher" button.

Quote:
Fatal error: Call to undefined function loadpheal() in C:\wamp\www\eve-charinfo\display.php on line 36
Call Stack
# Time Memory Function Location
1 0.0012 717608 {main}( ) ..\display.php:0




It's doing the same when i use your final api-tutorial-part4-end.zip

i don't understand why..



and, just for you know, i tried to post a msg on your blog, but it ask me password and login?
Jaqa
Royale Strategic Imperative
#19 - 2012-03-28 07:44:06 UTC  |  Edited by: Jaqa
Thanks a bunch, this is just what I was looking for.
I'm about to take the plunge and see what this is all about.


Seriously though, this is awesome.

The Original Jaqalope Pilot of the Transportosaurus Rex 100% Free Range