14/04
2016
Wallogit.com
2017 © Pedro Peláez
A simple class to shorten links using Bitly API
Bitly shortening class, (*1)
Simple class for shortening links using bit.ly; provides only link shortening, (*2)
Create a Bitly class object and pass an access token to it (you can use generic oauth token for that) like so:, (*3)
use KristobalJunta\Bitly;
$accessToken = 'your-access-token';
$bitly = new Bitly([
'access_token' => $accessToken
]);
You can also choose response format (either text, json or xml). Default is json:, (*4)
$bitly = new Bitly([
'access_token' => $accessToken,
'response_type' => 'text'
]);
Finally, use the shorten method:, (*5)
$shortenedUrl = $bitly->shorten('http://example.com');