Alex Rivera | Logout

How to call https://www.googleapis.com/plus/v1/people/me at google

Asked 2012-01-24T15:49:49.220
8

I am developing an Android application and need to get the "me" info from google but I always ends up in either response code 401 or 403. 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 by (note...code below is shortened):

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 here.

Now get the me info:

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 response code 401.

I have 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 response code 403 - Something like "Daily limit exceeded. Please sign up".

What am I doing wrong? what have I missed? How should this be done?

Thanks

// Edits below Some more investigation: I added a project into code.google.com/apis/console and took the key generated from there and put into the url, like: https://www.googleapis.com/plus/v1/people/me?key=my_generated_key&access_token=" + authToken. Now the call works fine and I

Edit
Report

1 Answer

1

Why don't some of you try to go to the Google Console. In this way you will be able to have access to to the tools you need to rectify at least 403 forbidden problems. DMC

answered 2012-03-22T03:00:16.510

Your Answer