Reputation: 393
I am trying to implement a shortened url feature in my web application.So I am using google shorten url api in angularjs using ajax but I am not getting anything in response.`
$http.post('https://www.googleapis.com/urlshortener/v1/url?key=#key','http://uihacker.blogspot.ca/2013/04/javascript-use-googl-link-shortener.html').success(function(data,status,headers,config){
$scope.shortUrl=data.id;
}).
error(function(data,status,headers,config){
});
`
Upvotes: 1
Views: 3252
Reputation: 3651
The request is not formed correctly based on google's docs. Try this:
$http.post('https://www.googleapis.com/urlshortener/v1/url?key=#key',{longUrl:'http://uihacker.blogspot.ca/2013/04/javascript-use-googl-link-shortener.html'}).success(function(data,status,headers,config){
$scope.shortUrl=data.id;
}).
error(function(data,status,headers,config){
});
Upvotes: 2