Really simple Bitly API client.
PHP 5+, json_decode(), bitly API Key
http://code.google.com/p/bitly-api/wiki/ApiDocumentation
There are now two different wrappers created for the Bit.ly API. There is one for version 2 and now the most current version 3. The reason there are now two different libraries is because the entire nomenclature of the result keys has switched from version 2 to version 3. Instead of remapping all the keys I chose to keep the version 2 file and create a version 3 file.
If you want to use any of the version 2 only methods, you must load the version 2 wrapper.
- shorten (v2, v3)
- expand (v2, v3)
- info (v2)
- stats (v2)
- errors (v2)
- validate (v3)
- clicks (v3)
- bitly_pro_domain (v3)
$bitly = new Bitly;
$res = $bitly->shorten(array(
'apiKey' => 'YOUR KEY',
'login' => 'YOUR USERNAME',
'longUrl' => 'YOUR URL'
));
$bitly = new Bitly_V2;
$res = $bitly->shorten(array(
'apiKey' => 'YOUR KEY',
'login' => 'YOUR USERNAME',
'longUrl' => 'YOUR URL'
));
$res = Bitly::shorten(array(
'apiKey' => 'YOUR KEY',
'login' => 'YOUR USERNAME',
'longUrl' => 'YOUR URL'
));
If you are do not use the static call-to-action you have access to other methods for error checking, error messages and getting direct information back. Any key returned under the 'result' can be returned using the 'get' method. Some examples are below.
$bitly = new Bitly;
$res = $bitly->shorten(array(
'apiKey' => 'YOUR KEY',
'login' => 'YOUR USERNAME',
'longUrl' => 'YOUR URL'
));
if ($bitly->is_error()) {
print $bitly->get('error');
}
else {
$short_url = $bitly->get('url');
$hash = $bitly->get('hash');
}
The array argument should be an array of keys and values. The keys corresponding to the API arguments and the values, well being the value you'd like to set.
You DO NOT have to set format param.