Question

I'm trying to access Google Analytics API from my BlackBerry's Mobile App (written in JavaScript) using Google's OAuth 2.0 procedure described here:

https://developers.google.com/accounts/docs/OAuth2InstalledApp .

I have no problem with it's first step - "Forming the URL". I've registered my App as "installed application" in the Google APIs Console (with redirect URIs - "urn:ietf:wg:oauth:2.0:oob" and "localhost"), and after logging in into the Google's account I'm obtaining an authorization code.

The problem arises when I'm trying to use this code to get Google's access token (which I could use later to connect with the Google Analytics API). I'm using the following XMLHttpRequest:

var req = new XMLHttpRequest();
req.open('POST', 'https://accounts.google.com/o/oauth2/token?code='+code+'&client_id='+clientId+'&client_secret='+clientSecret+'&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code', false);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send('');

and the response to this request is:

{"error" : "invalid_request"} .

What am I doing wrong? Any help will be greatly appreciated.

Was it helpful?

Solution

The query should be in the body of the POST request instead of the url. This is a common gotcha.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top