Pages: [1] :: one page |
|
Author |
Thread Statistics | Show CCP posts - 0 post(s) |
Lem2J
Black Sea Industries Insurgency
|
Posted - 2008.03.30 19:29:00 -
[1]
Edited by: Lem2J on 30/03/2008 19:34:48 Hey guys, im new to all of this, but im trying to put a class together in Php to speak with the API.. Hwere what i have so far:
<?php
class eveApi { var $api_userid = "123"; var $api_key = "123"; var $api_charid = "781335233"; var $api_root = "api.eve-online.com";
var $head; var $auth;
function apiRequest() { $fp = fsockopen ('api.eve-online.com', 80, $errno, $errstr, 30); if (!$fp) return "meh! Eve server is such a n00b'ette! ".$errstr;
fputs($fp, $this->head); fputs($fp, $this->auth);
$data=''; while (!feof($fp)) { $data.=fgets($fp,128); }
fclose ($fp);
$start = '<eveapi'; $end = '</eveapi>'; $null = eregi("$start(.*)$end", $data, $stuff);
return $stuff[0]; }
function starbaseList() { $this->head = "POST /corp/StarbaseList.xml.aspx HTTP/1.0\r\n"; $this->head .= "Host: api.eve-online.com\r\n"; $this->head .= "Content-Type: application/x-www-form-urlencoded\r\n"; $this->head .= "Content-Length: " . strlen($auth) . "\r\n"; $this->head .= "Connection: close\r\n\r\n";
$this->auth = "apiKey=" . $this->api_key; $this->auth .= "&characterID=". $this->api_charid; $this->auth .= "&userID=" . $this->api_userid;
print $this->apiRequest(); } } ?>
-----------
<?php
require_once('library/eve-api.class.php'); $api = new eveApi;
$stuff = $api->starbaseList(); print $stuff;
?>
For some reason, i am getting the error: 2008-03-30 19:32:53 Must provide userID parameter for authentication. 2008-03-30 19:37:53
As far as i can see, the correct details have been passed? Any help would be great :).
|
Arous Drephius
|
Posted - 2008.03.30 20:46:00 -
[2]
Couple of suggestions:
1) Use a class that has already been made and tested, rather than reinvent the wheel. 2) If you really want to make your own, try cURL instead of writing the HTTP request yourself.
|
Lem2J
Black Sea Industries Insurgency
|
Posted - 2008.03.30 22:14:00 -
[3]
You make some good points :p.. However id still like to understand why this wont work. As far as i can see, it should.
|
Tonto Auri
Vhero' Multipurpose Corp
|
Posted - 2008.03.30 22:21:00 -
[4]
Firstly, try cURL, either directly or through PEAR::Net_Curl wrapper. You'll see it solves a ton of headache and makes Your code much clearer. Secondly, to access /corp/ root, You need a FULL API key. Check that You have one, and not Limited key. -- Thanks CCP for cu<end of sig> |
Lem2J
|
Posted - 2008.03.30 22:39:00 -
[5]
Yea its deffo the full API key
|
Tonto Auri
|
Posted - 2008.03.30 22:43:00 -
[6]
You must also have required privileges to do the stuff in /corp/ root. Check that You can access same information from Your account at EVE-o website. -- Thanks CCP for cu<end of sig> |
Lem2J
Black Sea Industries Insurgency
|
Posted - 2008.03.30 23:32:00 -
[7]
Yep to both
|
DeTox MinRohim
Madhatters Inc. Pure.
|
Posted - 2008.03.31 07:25:00 -
[8]
Here:
$this->head .= "Content-Length: " . strlen($auth) . "\r\n";
There is nothing in your $auth. should be $this->auth but you fill it after wich is too late.
In starbaseList(), reverse the this->auth and this->head part, fix the line above... think it'll work.
------ This sig space is Read-only ! omgalink - Online Skillsheet |
DeTox MinRohim
Madhatters Inc. Pure.
|
Posted - 2008.03.31 07:33:00 -
[9]
Edited by: DeTox MinRohim on 31/03/2008 07:35:55 Few changes, basically, simplified a function and putting some stuff that is static into another.
<?php
class eveApi { var $api_userid = "123"; var $api_key = "123"; var $api_charid = "781335233"; var $api_root = "api.eve-online.com";
var $head; var $auth; var $target;
function apiRequest() { $this->auth = "apiKey=" . $this->api_key; $this->auth .= "&characterID=" . $this->api_charid; $this->auth .= "&userID=" . $this->api_userid; $this->auth .= "&version=2"; $this->head = $this->target; $this->head .= "Host: api.eve-online.com\r\n"; $this->head .= "Content-Type: application/x-www-form-urlencoded\r\n"; $this->head .= "Content-Length: " . strlen($this->auth) . "\r\n"; $this->head .= "Connection: close\r\n\r\n"; $fp = fsockopen ('api.eve-online.com', 80, $errno, $errstr, 30); if (!$fp) return "meh! Eve server is such a n00b'ette! ".$errstr; fputs($fp, $this->head); fputs($fp, $this->auth); $data=''; while (!feof($fp)) { $data.=fgets($fp,128); } fclose ($fp); $start = '<eveapi'; $end = '</eveapi>'; $null = eregi("$start(.*)$end", $data, $stuff); return $stuff[0]; } function starbaseList() { $this->target = "POST /corp/StarbaseList.xml.aspx HTTP/1.0\r\n"; print $this->apiRequest(); } } ?>
------ This sig space is Read-only ! omgalink - Online Skillsheet |
DeTox MinRohim
|
Posted - 2008.03.31 07:43:00 -
[10]
Edited by: DeTox MinRohim on 31/03/2008 07:44:14 ... scrap that... forum broke this post.
------ This sig space is Read-only ! omgalink - Online Skillsheet |
|
Lem2J
Black Sea Industries Insurgency
|
Posted - 2008.03.31 10:19:00 -
[11]
Cheers :/ cant believe i missed that
|
|
|
|
Pages: [1] :: one page |
First page | Previous page | Next page | Last page |