Created
March 16, 2010 19:59
-
-
Save danielfilho/334437 to your computer and use it in GitHub Desktop.
Encurtando URL com jQuery e bit.ly
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
(function($){ | |
// cedendo as informações | |
var defValues = { | |
login: '<<usuário bit.ly>>', // para registrar: http://bit.ly/account/register | |
apiKey: '<<sua API-key>>', // depois de registrar: http://bit.ly/account/your_api_key | |
version: '2.0.1', // versão compatível com este script | |
longUrl: '', | |
history: '0' | |
}; | |
// criando a URL de requisição | |
var bitlyURL = "http://api.bit.ly/shorten?" | |
+"version="+defValues.version | |
+"&longUrl="+defValues.longUrl | |
+"&login="+defValues.login | |
+"&apiKey="+defValues.apiKey | |
+"&history="+defValues.history | |
+"&format=json&callback=?"; | |
// Utilize the bit.ly API | |
$.getJSON(bitlyURL, function(data){ | |
// exibir a URL encurtada | |
$('#urlEncurtada') | |
.append(data.results[url].shortUrl); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment