0

I am trying to use bit.ly api to automatically shorten URLs for my blog but this code does not seem to be working

<script>getShortUrl: function(url, callback)
{
   var url = 'https://api-ssl.bitly.com/v3/shorten?access_token=***********************&longUrl=http%3A%2F%2Fwww.techforty.com';

    $.getJSON(
        url,
        {},
        function(response)
        {
            if(callback)
                callback(response.data.url);
        }
    );
},</script> 

Is there a quick and easy way to get short URL out of this script in an input box?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Avadhesh18
  • 27
  • 1
  • 9

1 Answers1

0

It looks like you're using this in an object. Here's the code

var App = {

getShortUrl: function(url, callback)
{

    $.getJSON(
        url,
        {},
        function(response)
        {
            if(callback)
                callback(response);
        }
    );
}
}

App.getShortUrl('https://api-ssl.bitly.com/v3/shorten?access_token=***********************&longUrl=http://www.techforty.com', function(response) {
    $('#result').html(response.data.url);
});
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
elzi
  • 5,442
  • 7
  • 37
  • 61