Code Snippets and More

First, in order to use the API, you must sign up and get an api key. Once done, with cURL we can short a URL calling the next simple PHP function

function shortUrl ($url) {
    $bitlyUser = 'TEST';
    $apiKey = 'API_KEY';
    $ch = curl_init();
    //cURL options
    curl_setopt($ch, CURLOPT_URL, '' . $bitlyUser . '&apiKey=' . $apiKey . '&uri=' . htmlspecialchars($url) . '&format=txt');
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $ret = curl_exec($ch);
    return $ret;

Recent comments

© 2014 Copyright by Keyvan Akbary