Skip to content

Instantly share code, notes, and snippets.

@danielfilho
Created March 16, 2010 19:59
Show Gist options
  • Save danielfilho/334437 to your computer and use it in GitHub Desktop.
Save danielfilho/334437 to your computer and use it in GitHub Desktop.
Encurtando URL com jQuery e bit.ly
(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