Hello Readers,
Bitly API is a way to shrink long URLs so that we can share it on social media. For example on twitter we can't share long URL so it is a very easy way to shorten long URLs. The most important thing is no server side code required.
To use bit.ly API first of all we need to create an account and logged in on bitly.
To signup / login click here - bitly.com
Here is the example to shrink URLs using bit.ly API:
var bitlyData = {};
bitlyData['login'] = login;
bitlyData['apiKey'] = api key;
bitlyData['longUrl'] = your long url;
bitlyData['format'] = "json";
$.ajax({
url: 'http://api.bitly.com/v3/shorten?',
data: bitlyData,
success: function (data){
console.log(JSON.stringify(data));
},
error: function(e) {
alert("err:"+JSON.stringify(e))
}
});
In the above example, To get the values of login, apiKey click here - get your api key and the longUrl is url which you want to shink.
Hope this will help you :)
0 Comment(s)