ipernity / PHP API Kit (v0.9)

This PHP API Development Kit requires PHP 5.2 or higher and CURL extension. This toolkit provides some basic functions to perform API calls and user authentication. Results can be returned in JSON, XML or serialized PHP.

Keep your API secret safe.



pear install -of https://s.ipernity.com/E/API_Kits/PHP/Iper_API/Iper_API-latest.tgz


Download Iper_API, unzip (tar/gz) and copy API.php in your website directory.


require 'API.php';

$api = new Iper_API(array('api_key'=>'8da10d4c00000001155dac4aa33cb785',

$r = $api->request('test.echo',array('echo'=>"you're smart!"));

if ( $r )
  print 'API replied: '.$r['echo'];
  print 'An error occured: '.$api->getErrorMessage();


function Iper_API(conf)

The class constructor. Uses setConf(conf) to set configuration values.

function setConf(conf)

conf is an array() of configuration parameters:

JSON responses are decoded using json_decode(data,true) with assoc boolean true by default. Change the class property $api->_json_assoc to false if you prefer to receive a JSON object.

function setAppName(string $name)

Enter your application name if you'd like it to be sent in the HTTP User-Agent header.

function request(string $method, [array $params], [boolean $with_auth_token])

Parameters :

The request class method will take care of signing your request.

Returns :

function getAuthUrl(array $perms, [string $frob])

Parameters :

Returns : an URL

function getFrob()

Uses the request() method to perform an auth.getFrob API call. Returns a frob or false.

function getToken(string $frob)

Uses the request() method to perform an auth.getToken API call. Returns a token or false. When successful, the authentication information is stored into the $this->_auth property.
Authenticated calls can be done by adding the auth_token in the request parameters or by setting the flag with_auth_token (see the request() function).

function checkToken(string $token)

If the token is omitted the function will check the current token (if getToken() was called earlier). Returns a true or false. When successful, the authentication information is stored into the $this->_auth property.

function getAuth()

Returns the $this->_auth array.

function unauthenticate()

Removes authentication information e.g. resets $this->_auth.

Another demo...

// we assume this script is your callback url.

require 'API.php';

$api=new Iper_API(array('api_key'=>'6fa87ba500002712bd4eed6020f3bd72',

$api->setAppName('My supercool app');

// authenticate
if ( $_GET['frob'] )
  $token = $api->getToken($_GET['frob']);
  if ( ! $token ) die($api->getErrorMessage());

  // call with auto-authentication

  $r = $api->request('account.getQuota',array(),true);


  $url = $api->getAuthUrl(array('doc'=>'write'));
  print '<a href="'.$url.'">click here to authorize this app</a>';

One last thing...

Have fun and let us know if you need any help.