ortense
5/13/2014 - 4:31 PM

Function to shorten url by bit.ly

Function to shorten url by bit.ly

/**
 * @function bitLy
 * @param {string} long_url - Long URL to shorten
 * @param {function} func - receives short url
 */
function bitLy(long_url, func){
	$.getJSON(
		"http://api.bitly.com/v3/shorten?callback=?", 
		{ 
			"format": "json",
			"apiKey": "your_api_key",
			"login": "your_login",
			"longUrl": long_url
		},
		function(response)
		{
			func(response.data.url);
		}
	);
}