0

i am tyring to get google api token by sendding auth code to google following this guide.

this is my code:

        $http({
            method: 'POST',
            url: 'https://accounts.google.com/o/oauth2/token',
            headers: {'Content-Type': 'application/x-www-form-urlencoded'},
            params : {
                code           : '4/heMv6ozWwCxS5RyTzCgThAgxvRyk.oske-bNEGOUTOl05ti8ZT3YnwwH8iQI',
                client_id      : GoogleAppInfo.clientId,
                 redirect_uri  : GoogleAppInfo.redirect_uri,
                client_secret  : GoogleAppInfo.client_secret,
                grant_type     : 'authorization_code'
            }

        }).
        success(function(data, status, headers, config) {
            alert('secsses');
        }).
        error(function(data, status, headers, config) {
            alert('error');

        });

the reuqest sended but the header is not set! enter image description here

has anyone know what is the problem?

Tomer Pearl
  • 107
  • 9

1 Answers1

1

From: Angular, content type is not being sent with $http

"You need to include a body with the request. Angular removes the content-type header otherwise.

Add data: '' to the argument to $http."

Community
  • 1
  • 1
Mathew Berg
  • 28,625
  • 11
  • 69
  • 90
  • thanks! that worked. the header was added. but it didnt solve the problem. google server still retirives bad request eror. – Tomer Pearl Mar 26 '14 at 12:40
  • I suggest adding another question perhaps with different tags now that the problem has shifted to communicating with the google server. I do not have experience with that, sorry. – Mathew Berg Mar 26 '14 at 12:41
  • well i have dont that. thanks for the help. my other question is http://stackoverflow.com/questions/22661673/cant-get-access-token-from-google-using-angularjs – Tomer Pearl Mar 26 '14 at 12:54