Created
February 1, 2014 21:59
-
-
Save travismillerweb/8759574 to your computer and use it in GitHub Desktop.
JS - Bitly API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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