jqueryjsonurl-rewritingurl-shortenergoogle-url-shortener

google url shortener not returning a url


i am just trying to make a simple ajax call to shorten a url using googles url shortener, but its not returning any data. Anyone have any ideas?

$.ajax({
                  type: 'POST',
                  url: "https://www.googleapis.com/urlshortener/v1/url",
                  contentType: 'application/json',
                  data: {longUrl: match},
                  dataType: 'json',
                  success: function(id){
                  $('#menu').html(id);
                  }
                });

I have an API key but i just didnt put it in here. and you dont need one to use the service.


Solution

  • Use the api library rendered by google for url shortner, its available in php, java , .net etc.,

    Link to API libraries - http://code.google.com/apis/urlshortener/libraries.html

    Else your ajax need to done for cross domain ajax, read this