I am developing an Android application and need to get βIβ information from google, but I always get either a 401 or 403 response code. What am I doing wrong? Here is my code:
private static final String GOOGLE_AUTH_TOKEN_TYPE = "oauth2:https://www.googleapis.com/auth/plus.me";
I get the oauth token (note ... the code below is abbreviated):
Account googleAccount = (AccountManager) getSystemService(ACCOUNT_SERVICE).getAccountsByType("com.google")[0]; final Bundle bundle = manager.getAuthToken(googleAccount, GOOGLE_AUTH_TOKEN_TYPE, true, null, null).getResult(); String authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN);
So far, so good ... I now have a token, so everything looks good.
Now get the information:
String GOOGLE_ME_URL = "https://www.googleapis.com/plus/v1/people/me"; final DefaultHttpClient client = new DefaultHttpClient(); final HttpGet request = new HttpGet(GOOGLE_ME_URL); request.addHeader("Authorization", "OAuth=" + authToken); final HttpResponse response = client.execute(request);
This gives a response code of 401.
I also tried:
final DefaultHttpClient client = new DefaultHttpClient(); final HttpGet request = new HttpGet(GOOGLE_ME_URL + "?access_token=" + authToken); final HttpResponse response = client.execute(request);
This gives an answer code of 403 - Something like "Exceeding the daily limit. Please register."
What am I doing wrong? what did I miss? How to do it?
thanks
// Editing below Some more research: I added the project to code.google.com/apis/console and took the generated key and put it in the URL, for example: https://www.googleapis.com/plus/v1/people/ me? key = my_generated_key & access_token = "+ authToken. Now the call works fine and I get a 200 response with the correct information. But I really donβt want to use this method if I donβt need and according to google I donβt need." If the request requires authorization (for example, a request for individual private data), then it should include an OAuth 2.0 token. It may also include an API key, but this is optional. "- from developers.google.com/+/api/oauth.
Another thing: If I try to use a different URL " https://www.googleapis.com/oauth2/v1/tokeninfo?access_token= " + authToken it works fine.
android oauth token
user1140596
source share