Created
November 24, 2009 15:22
-
-
Save mataspetrikas/241931 to your computer and use it in GitHub Desktop.
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
var shortenUrl = function(longUrl) { | |
var apiLogin = 'yourapilogin', | |
apiKey = 'yourApiKey'; | |
// call the bit.ly service | |
$.getJSON('http://api.bit.ly/shorten?callback=?', { | |
long_url: mediaUrl, | |
version: '2.0.1', | |
login: apiLogin, | |
api_key: apiKey, | |
format: 'json', | |
history: 1 | |
}, function(data){ | |
try{ | |
var shortUrl = data.results[mediaUrl].shortUrl; | |
if(shortUrl && shortUrl !== 'undefined'){ | |
// do here something with the shortened url | |
} | |
}catch(msg){ | |
// bit.ly failed, try something else | |
} | |
}); | |
}; | |
// example | |
shortenUrl('http://tracksonamap.com/#city-8457'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment