1

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){

            });

`

8

1 Answer 1

2

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){

        });
Sign up to request clarification or add additional context in comments.

2 Comments

Are you sure you've got a valid key? And also that you're not actually inserting # into the start of your key?
By the way, if you're using chrome there are more developer tools than just the console. In the "Network" tab, click on the failed call to get more detailed information about it. For example, if your key is invalid then the response would say something like: "errors": {"domain": "usageLimits", "reason": "keyInvalid", "message": "Bad Request"}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.