Tag: url shorteners
URL Shortening on your site
by Jay on Jul.15, 2010, under API, PHP, Technology, jQuery
A nice feature to have on a site would be that of a URL shortener. I’ve looked at some of the more popular ones and decided to play with the API of the most popular, http://bit.ly.
I selected bit.ly as it is the most widely used, your account can be integrated with your Twitter client (Twitter for iPhone for example) and most impressively, you can get real time statistics on the shortened URL’s you create. This would be very useful for those companies who wish to track their marketing campaigns running on their website/twitter/Facebook accounts.
In the spirit of exploration, I’ve created a simple PHP bit.ly class, called bitlyApi.class.php.
To get up and running with this, I first created a new bit.ly account and copied out the API key they provide. Once you create an account, you will have access to the realtime statistics feature, otherwise you’ll just get the bog standard URL shortener service.
The bit.ly API is really straight forward. Have a look at the previous link to see what you can do.
Taking the most obvious function, URL shortening, the class simply takes in a valid URL, puts together the API request and sends it along with my username and API key and in return a JSON encoded string.
Download the sample code and have a look here at the live demo.
Note, that the code supplied is not production ready. I would need to have your usual input validation etc..
Feel free to comment!