Bitly is the most popular website to shorten links in the world. According to the statistics, Internet users add 80 million new links each day, and the number of clicks per month exceeds 8 billion. Using the service is easy and intuitive. The API is friendly to use and integration of the system on website is very simple.


Bitly is most often used to generate a link to share on twitter or facebook.

We need to start by opening an account in website. We can do this by using Facebook, Twitter, or traditionally via email.

The next step is to get our API key.

Click the link in the upper right corner with out login as „ahoy, bartlomiej.makowski”. Drop-down list will appear, then select „SETTINGS”.

Head towards the upper tabs and select „ADVANCED”.

The last item on the subpage is „Legacy API Key”. Click on the „Show Legacy API Key” and get the key.


This information will be useful for us, when writing a function:

   function bitly($url){
        //login info 
        $login = 'LOGIN';   //your login  
        $apikey = 'API-KEY'; //your API key  
        $format = 'json';   //choose between json or xml  
        $version = '2.0.1';  
        //generating URL  
        $bitly = ''.$version.'&longUrl='
        //fetching url  
        $response = file_get_contents($bitly);  
        //for json  
        if(strtolower($format) == 'json')  
            $json = @json_decode($response,true);  
            return $json['results'][$url]['shortUrl'];  
        else //for xml
            $xml = simplexml_load_string($response);  
            return ''.$xml->results->nodeKeyVal->hash;  

Please write in the comments if you are using bitly on your own pages.

Related Posts Plugin for WordPress, Blogger...

Leave a comment

Twój adres email nie zostanie opublikowany. Pola, których wypełnienie jest wymagane, są oznaczone symbolem *