Check phplicengine/bitly as a possible replacement.
PHP Library based on Guzzle to consume Bit.ly API.
The biggest advantage in using Guzzle is that you can easely attach Guzzle plugins to your client. Here, for example,you can see how to attach the log plugin and write all your requests to a file.
An integration with Symfony2 is available as well.
- branch
master
follows psr4 standards and get2.x
tags - branch
psr0
follows, of course, psr0 standards and get1.x
tags - No new features only bugfix
This project follow semantic versioning.
The recommended way to install this library is through Composer. For information about Composer and how to install in look here.
From the command line run
./composer create-project hpatoio/bitly-api your_prj_dir '~2.0'
Move into your project directory and run
./composer require hpatoio/bitly-api '~2.0'
or add to your composer.json
{
...
"require": {
...
"hpatoio/bitly-api": "~2.0"
}
}
and run
./composer update
<?php
// This file is generated by Composer
require_once 'vendor/autoload.php';
# To find your bitly access token see here https://bitly.com/a/oauth_apps
$my_bitly = new \Hpatoio\Bitly\Client("insert_here_your_bitly_api_access_token");
$response = $my_bitly->Highvalue(array("limit" => 3));
print_r($response);
It might be that bit.ly is unreachable and you want to set a specific timeout. Just set the cURL timeout options in the client:
$my_bitly = new \Hpatoio\Bitly\Client("insert_here_your_bitly_api_access_token");
// set cURL timeout, you can specify any cURL options
$my_bitly->setConfig(array(
'curl.options' =>
array(
CURLOPT_TIMEOUT => 2,
CURLOPT_CONNECTTIMEOUT => 2
)
));
$response = $my_bitly->Highvalue(array("limit" => 3));
print_r($response);
To get the method name remove "v3" from the API url and camelize the other words removing the slashes.
Examples:
- /v3/highvalue -> Highvalue
- /v3/realtime/hot_phrases -> RealtimeHot_phrases
- /v3/link/content -> LinkContent
At the moment the library supports these APIs:
You need to copy Behat default configuration file and enter your access_token
option there.
$ cp behat.yml.dist behat.yml
Now open behat.yml
and change the string your_bitly_access_token_here
with your access token.
Run the suite typing
$ bin/behat
A Symfony2 bundle that integrate this library is available here
Here you can see how to attach Guzzle Log plug to your client and save all your requests to a file.
NB: To run this script you need monolog/monolog
<?php
// This file is generated by Composer
require_once 'vendor/autoload.php';
use Guzzle\Log\MessageFormatter;
use Guzzle\Log\MonologLogAdapter;
use Guzzle\Plugin\Log\LogPlugin;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
$logger = new Logger('client');
$logger->pushHandler(new StreamHandler('/tmp/bitly_guzzle.log'));
$adapter = new MonologLogAdapter($logger);
$logPlugin = new LogPlugin($adapter, MessageFormatter::DEBUG_FORMAT);
# To find your bitly access token see here https://bitly.com/a/oauth_apps
$my_bitly = new \Hpatoio\Bitly\Client("your_bitly_access_token");
$my_bitly->addSubscriber($logPlugin);
$response = $my_bitly->Highvalue(array("limit" => 3));
print_r($response);
Now in /tmp/bitly_guzzle.log
you can see all your requests.