PHP code example of frankfoerster / cakephp-bitly

1. Go to this page and download the library: Download frankfoerster/cakephp-bitly library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

frankfoerster / cakephp-bitly example snippets


Plugin::load('FrankFoerster/Bitly');

return [
    ...
    
    'Bitly' => [
        'login' => 'YOUR_LOGIN',
        'apiKey' => 'YOUR_API_KEY',

        /**
         * @link: http://book.cakephp.org/3.0/en/core-libraries/httpclient.html#proxy-authentication
         *
         * e.g.:
         * -----
         * 'proxy' => [
         *   'username' => 'foo', // optional username set in request header
         *   'password' => 'bar', // optional password set in request header
         *   'proxy' => 'tcp://localhost:9000'
         * ]
         */
        'proxy' => false
    ],
    
    ...
];

use FrankFoerster\Bitly\Exception\BitlyException;
use FrankFoerster\Bitly\UrlShortener;

$urlShortener = new UrlShortener();

try {
    $shortUrl = $urlShortener->shorten($myLongUrl);
} catch (BitlyException $e) {
    // handle any of the exceptions
}