Skip to content

Instantly share code, notes, and snippets.

@travismillerweb
Created February 1, 2014 21:59
Show Gist options
  • Save travismillerweb/8759574 to your computer and use it in GitHub Desktop.
Save travismillerweb/8759574 to your computer and use it in GitHub Desktop.
JS - Bitly API
/*
Reference Link: http://stackoverflow.com/questions/4760538/using-only-javascript-to-shrink-urls-using-the-bit-ly-api
*/
function get_short_url(long_url, login, api_key, func)
{
$.getJSON(
"http://api.bitly.com/v3/shorten?callback=?",
{
"format": "json",
"apiKey": api_key,
"login": login,
"longUrl": long_url
},
function(response)
{
func(response.data.url);
}
);
}
/*
Sign up for Bitly account at
https://bitly.com/a/sign_up
and upon completion visit
https://bitly.com/a/your_api_key/
to get "login" and "api_key" values
*/
var login = "LOGIN_HERE";
var api_key = "API_KEY_HERE";
var long_url = "http://www.kozlenko.info";
get_short_url(long_url, login, api_key, function(short_url) {
console.log(short_url);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment