Kiwwito

Code Snippets and More

First, in order to use the bit.ly 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, 'http://api.j.mp/v3/shorten?login=' . $bitlyUser . '&apiKey=' . $apiKey . '&uri=' . htmlspecialchars($url) . '&format=txt');
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  
    //Execution
    $ret = curl_exec($ch);
    curl_close($ch);
    
    return $ret;
}

Recent comments

© 2014 Copyright by Keyvan Akbary