How to call https://www.googleapis.com/plus/v1/people/me on Google

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.

+8
android oauth token
source share
6 answers

The problem is with the simple api key passed to the request.

If the key parameter is not included in the request or the Google+ API was not activated for this project, you will receive an error message: Msgstr "Daily limit exceeded. Please register."

To solve this problem, you need to do the following:

  • Visit the Google API Console here: https://code.google.com/apis/console/?api=plus
  • In the Services panel, make sure the Google+ API is turned on.
  • In the API console, click the Access API icon in the menu on the left.
  • Copy the API key shown below.
  • Include this API key in your HTTP request.
 GOOGLE_ME_URL + "?access_token=" + authToken + "&key=" + MY_SIMPLE_API_KEY 
+13
source

Most new Google APIs have quotas (for example, daily usage restrictions), and some even support billing (where you get bills for calling the API). These quotas and billing are calculated for each developer project, and not for each user, so Google should know which application will use your API.

API clients using Google OAuth 2.0 are generally required to register and receive a client identifier and client secret.

This client ID and client secret are returned by the Google APIs console: code.google.com/apis/console.

Then you use these values ​​in your application and it identifies your application and allows Google to assign your use of the API to your developer account / project.

In the AccountManger interface that you use, the client ID is not transmitted by your application, so Google cannot determine which quota of the developer / project account is deducted for use. He also does not know that the API was correctly enabled (TOS accepted, etc.) by you as a developer. That's why he asks you to "please register" and report that the "daily limit has been exceeded" (since an unregistered limit is a zero request for many APIs).

In this case, you need to pass the value "key", as it was done to access the API with OAuth 2.0 tokens obtained from AccountManager.

+3
source

Why some of you are not trying to go to the Google Console. Thus, you can access the tools necessary to fix at least 403 forbidden problems . DMC

+1
source

You are using http at the moment, but in fact you are calling the site on top of https. Either use the secure connection procedure, or use the http: // address.

(Sorry, could not do it yet)

0
source

Create a new authentication token and secret for your application and try again.

This may solve your problem, but your daily snooze limit may be exhausted ...

I had the same problem as you.

0
source

I have the same problem that you just need to enable google + api in the console enjoy :)

0
source

All Articles