PHP library to consume bit.ly API
The recommended way to install this library is through Composer.
composer require gabrielkaputa/bitly
First of all, create a bit.ly account if you don't have one already.
If all you need to do is to create shortlinks on behalf of a single user or site, all you need is to get your generic access token. When done, you can create shortlinks like this:
require_once("vendor/autoload.php");
$bitly = \GabrielKaputa\Bitly::withGenericAccessToken(GENERIC_ACCESS_TOKEN);
$short_url = $bitly->shortenUrl($long_url);
Another option is when you are working with multiple end-users or to pull any information on a user level
for your own account. In this case you will need to register your application
to get your CLIENT_ID
and CLIENT_SECRET
. When done, you can create shortlinks like this:
require_once("vendor/autoload.php");
$bitly = \GabrielKaputa\Bitly::withCredentials(CLIENT_ID, CLIENT_SECRET, USERNAME, PASSWORD);
$short_url = $bitly->shortenUrl($long_url);