A PHP wrapper for the bit.ly API. This package use Bitly API version v4.
Install via composer
composer require codehaveli/bitly-php:dev-master --prefer-source
<?php
require 'vendor/autoload.php';
use Codehaveli\Bitly;
use Codehaveli\Exceptions\BitlyErrorException;
// First setup your credentials provided by Bitly
$accessToken = "ACCESS_TOKEN_FROM_BITLY";
$guid = "GUID_FROM_BITLY";
Bitly::init($accessToken, $guid);
Once credentials are set you can use available resources.
Resources availables:
- Link
- Available methods:
getUrl
- Available methods:
<?php
use Codehaveli\Bitly;
use Codehaveli\Exceptions\BitlyErrorException;
Bitly::init($access_token, $guid);
$link = Bitly::link();
try {
$shortLink = $link->getUrl("https://www.codehaveli.com/"); // https://bit.ly/3lF0yKR
} catch (BitlyErrorException $e) {
$code = $e->getCode();
$message = $e->getMessage();
}
This is not a Official SDK of Bitly Please read privacy and terms of service of Bitly before use.
- Wordpress Plugin by Codehaveli Codehaveli Bitly URL Shortener
- Bitly API Documentation
- Codehaveli Blog