Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mataspetrikas/241931 to your computer and use it in GitHub Desktop.
Save mataspetrikas/241931 to your computer and use it in GitHub Desktop.
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