Pages: [1] :: one page |
|
Author |
Thread Statistics | Show CCP posts - 0 post(s) |
Flashetta
|
Posted - 2008.12.17 18:59:00 -
[1]
Hello.. i'm fairly new to PHP, but i was wondering if someone could explain how this (from the API page), can be done in PHP:
####################################### import httplib, urllib
params = urllib.urlencode( { 'characterID': 150209812, 'userid': 256833, 'apikey': 'DVPtgNgmyEGk9L9RxDTJn8dCjIraiaa7efNK4VlGKAoI6Hm8uB514zy6CbFCuScC', } )
headers = { "Content-type": "application/x-www-form-urlencoded" } conn = httplib.HTTPConnection("api.eve-online.com") conn.request("POST", "/char/WalletTransactions.xml.aspx", params, headers)
response = conn.getresponse() print response.status, response.reason
data = response.read() print data
conn.close #######################################
Just kinda need to know how to get started lol... then i'll research from there i suppose, but as is, i can't even look at the output of this as my server doesn't to .asp
Thanks!
|
Gilgamoth
Eldritch Storm The Matari Consortium
|
Posted - 2008.12.17 20:22:00 -
[2]
You might want to blank out the Character ID userid and API key. They are kinda personal..
The rest creates a connection to the server asks for your wallet transactions then outputs them
Regards,
Gil
Live on Eden Underground Radio every Wednesday 19:00 - 21:00 GMT. |
Dragonaire
Caldari Corax.
|
Posted - 2008.12.17 21:05:00 -
[3]
I'd suggest you go to Eve-Dev and have a look around there since more than one person has done a lot of the hard work already and made libraries for the API in several other languages including PHP. -- Finds camping stations from the inside much easier. Designer of Yapeal for Eve API. |
Flashetta
|
Posted - 2008.12.17 21:33:00 -
[4]
Thx dragonaire! Pretty useful site.
|
Lumy
Minmatar eXceed Inc. Triumvirate.
|
Posted - 2008.12.17 21:37:00 -
[5]
There are at least three ways how to do it in PHP:
1. raw fsockopen - "simply" build up the whole request yourself and send it to server
$params = array('userID'=>12345, 'apiKey' => 'someapikey'); $poststring = http_build_query($params); $fp = fsockopen($host, $port, $errno, $errstr, 30);
if (!$fp) { throw new Exception($errstr, $errno); }
// request the xml fputs ($fp, "POST " . $path. " HTTP/1.0\r\n"); fputs ($fp, "Host: " . $host . "\r\n"); fputs ($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); fputs ($fp, "User-Agent: PHPApi\r\n"); fputs ($fp, "Content-Length: " . strlen($poststring) . "\r\n"); fputs ($fp, "Connection: close\r\n\r\n");
if (strlen($poststring) > 0) { fputs ($fp, $poststring."\r\n"); }
// retrieve contents $contents = ""; while (!feof($fp)) { $contents .= fgets($fp); } fclose($fp);
2. curl - mostly supported on any hosting, probably best way
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); if ($params) { curl_setopt($ch, CURLOPT_POSTFIELDS, $params); } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); $contents = trim(@curl_exec($ch));
//chceck for connection errors $errno = curl_errno($ch); if ($errno > 0) { $errstr = curl_error($ch); //TODO: API exception curl_close ($ch); throw new Exception($errstr, $errno); }
curl_close ($ch);
3. HTTP module - some hostings does not support it, but it's easiest way
$request = new HttpRequest(); $request->setURL($url); $request->addPostFields($params); $response = $request->send(); $content = $response->getBody();
But as Dragonaire already mentioned, try to use some already cooked API Library.
Joomla! in EVE - IGB compatible CMS. |
Tonto Auri
Vhero' Multipurpose Corp
|
Posted - 2008.12.19 00:25:00 -
[6]
Originally by: Lumy 3. HTTP module - some hostings does not support it, but it's easiest way
$request = new HttpRequest(); $request->setURL($url); $request->addPostFields($params); $response = $request->send(); $content = $response->getBody();
But as Dragonaire already mentioned, try to use some already cooked API Library.
Last you mentioned looks much like PEAR::Http_Request. If so, you can install PEAR framework on any hosting with PHP support. -- Thanks CCP for cu |
Dragonaire
Caldari Corax.
|
Posted - 2008.12.19 00:50:00 -
[7]
You can usually install PEAR is true but some hosting companies make it hard. That's one reason I switched Yapeal away from it because it made it much harder for people to use. Someone who used ADOdb in his project suggested ADOdb to me and I've been very happy since I switched because I just include it with my code and then users don't have worry about any outside dependences. -- Finds camping stations from the inside much easier. Designer of Yapeal for Eve API. |
Tonto Auri
Vhero' Multipurpose Corp
|
Posted - 2008.12.19 00:57:00 -
[8]
Then you don't know much about PEAR. PEAR as library do not linked to it's location and could be included from any place. Only real requirement is that it's root should be available through include_path, but even that demand could be avoided by manual inclusion of all required files. Only PEAR installer cares about it's location and directory structure. -- Thanks CCP for cu |
Dragonaire
Caldari Corax.
|
Posted - 2008.12.19 01:09:00 -
[9]
Trying to include PEAR so people wouldn't have to install it themselves was a lot harder and took up several times more disk space then making the switch. I really like PEAR and used it a lot in my other projects. It wasn't until I had to start dealing with working everywhere with every host doing stuff different that I've decided it's much easier to use code that isn't dependent on it. -- Finds camping stations from the inside much easier. Designer of Yapeal for Eve API. |
Tonto Auri
Vhero' Multipurpose Corp
|
Posted - 2008.12.22 02:08:00 -
[10]
I'm dealing with it through one string in documentation: "PEAR::MDB2 ver. 2.4 Required" Honestly, if you're PHP programmer, you know what to do, if you're casual user, hire professional, cause they want to eat not less than you. Of course, it all depends on the size of a project. But mind you, less dependency typically means your application more sensitive to wrong hands. -- Thanks CCP for cu |
|
Dragonaire
Caldari Corax.
|
Posted - 2008.12.22 07:50:00 -
[11]
Your way of deal with it seems to be to exclude people from using what you write where I try to make it easier for people to use my code which seems to make a lot of them happy that I go to the extra effort for them. Guess maybe it's because I remember a time long ago in software where you didn't try to get all the money you could up front and then give bad support for even more money but instead charged a reasonable amount for the software or even gave it away and then charged a fair price for good support and had loyal customers that stayed with you for years not because they felt it was their only choose having paid so much but instead because they felt they were getting a good product and you actually cared about having them use it.
Seems to work for CCP with Eve they give away the software and free upgrades and just charge a reasonable fee to use it with their servers. Seems to also work for the people in several open source projects like Linux, Apache, MySQL, and PHP for some more examples that come to mind and I think you'd find it hard to find any hosting sites that don't offer packages with those available but it's much harder to find ones that offer ASP and MSSQL, etc. and the numbers that do continue to go down and the prices seem to keep going up.
So maybe I not as out of date as you seem to think I might be since we're going back to the way it use to be again -- Finds camping stations from the inside much easier. Designer of Yapeal for Eve API. |
Madam Mika
Gallente Shadow-Triad Lost Sheep Domain
|
Posted - 2008.12.22 09:00:00 -
[12]
Tonto Auri
got powned Your signature is too large. Please resize it to a maximum of 400 x 120 with the file size not exceeding 24000 bytes. If you would like further details please mail [email protected] Applebabe |
Pwett
Minmatar QUANT Corp. QUANT Hegemony
|
Posted - 2008.12.22 20:28:00 -
[13]
Edited by: Pwett on 22/12/2008 20:30:31 I personally like cURL and my XML in arrays - if you want the xml2array function I can post it. This is a little bit more involved than the above.
/** * Modified from Ix Forres(eve-dev) */ function apiRequest($target,$paramarray = array(), $output = FALSE) { $ch = curl_init(); $paramarray['userID'] = $this->userid; $paramarray['apiKey'] = $this->apikey; $t = "?"; foreach ($paramarray as $k=>$v) { $t .= $k."=".$v."&"; } $t = rtrim($t,'&');
curl_setopt($ch,CURLOPT_URL,$this->apiroot.$target.$t); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); $res = curl_exec($ch); curl_close($ch);
$doc = new DOMDocument(); $doc->loadXML($res); $doc->normalizeDocument(); $xmlArray = $this->xml2array($doc);
/* extra output calls for my personal use here */
return $xmlArray; }
_______________ Pwett Founder <Q> QUANT Hegemony
|
Dragonaire
Caldari Corax.
|
Posted - 2008.12.22 21:05:00 -
[14]
Or there my function currently in (it needs to be moved) inc/common_db.inc called getAPIinfo() that should be easily adapted for other uses that returns the XML as a simplexml element. I'd still recommend use one of the existing libraries, mine or one of the others, and save yourself the time re-inventing the wheel which might be better spent on the rest of your application. -- Finds camping stations from the inside much easier. Designer of Yapeal for Eve API. |
Tonto Auri
Vhero' Multipurpose Corp
|
Posted - 2008.12.23 17:53:00 -
[15]
You'd better use .php extension for all your PHP files due to security reasons. Name it .inc.php if you want.
P.S. If we speaking about end-users, for website it is people who visit it through their browsers. If you're working on the server side, you're a developer, and your explanation do not apply. Personally, if I distribute my PHP code as standalone application, it is one .phar file. Feel free to find where PEAR/Smarty ends and my own code begins, 'cause i'm using both libraries to it's full potential where possible. I'm not immortal, spending time catching all possible casualties in my own code is not what I would like to do in the rest of my life, if it is done already by someone else. I honestly understand your arguments, I just not follow your way in my life. Cheers! /me -- Thanks CCP for cu |
Dragonaire
Caldari Corax.
|
Posted - 2008.12.24 00:11:00 -
[16]
If I was making a complete application I might decide to do it differently but since for the Eve API I'm just making a 'library' that others use to access the API data the less dependences and easier to use it is while still leaving it open so others can add to it and if I'm lucky supply fixes for bugs they find the better it is. I've already had several people contact me about things they've found after they started using it that I never run into during testing because of the limits I have on testing stuff with just my characters. There has been several things that I've done differently and needed to be done differently as a library developer than you might as a application developer with end users and it has also been different because I'm developing it as an open source project vs a commercial 'black box' type library.
BTW I'm thought about changing the names on all my *.inc files over to using *.inc.php but there's the fact that most webservers will default to sending it as a plain text file if someone does access it directly vs if I change it to the other it will try to run it and could get lost or usually with the code I have add to the start of them just exit and leave them with a blank screen. Since there isn't anything really sensitive about what's in them I've not bothered to change them from what I'd been in the habit of naming them. Sometime in the future I may decide the benefits to changing them outweigh not and I'll have to be a little less lazy (only have made a little over 50 commits to the subversion so far this month ) and change the names on all of them and in all the other files' require_onces etc -- Finds camping stations from the inside much easier. Designer of Yapeal for Eve API. |
DeTox MinRohim
Madhatters Inc. The Initiative.
|
Posted - 2008.12.24 00:49:00 -
[17]
Edited by: DeTox MinRohim on 24/12/2008 00:56:43
Originally by: Dragonaire
BTW I'm thought about changing the names on all my *.inc files over to using *.inc.php but there's the fact that most webservers will default to sending it as a plain text file if someone does access it directly
REEDit:... yea... nvm, reading you more carefully, you want your .inc to show as plain text. My bad ------ This sig space is Read-only ! omgalink - Online Skillsheet |
Pwett
Minmatar QUANT Corp. QUANT Hegemony
|
Posted - 2008.12.30 19:55:00 -
[18]
Originally by: Tonto Auri You'd better use .php extension for all your PHP files due to security reasons. Name it .inc.php if you want.
I know this is completely off topic, but you can simple put
AddType application/x-httpd-php .inc
in your htaccess so you don't need to rename all the files and fix all the required (if security is required) _______________ Pwett Founder <Q> QUANT Hegemony
|
Arous Drephius
Perkone
|
Posted - 2008.12.30 20:12:00 -
[19]
Originally by: Pwett if security is required
Security is always required. No exceptions, ever.
Make sure you always put a .php extension on any PHP code you write in case you move it to another host or you give the code to someone else that doesn't set up the server config to treat it as PHP.
|
|
|
|
Pages: [1] :: one page |
First page | Previous page | Next page | Last page |