I'm trying to perform some read-only requests against the Google+ API - mainly to read some Activities. This is a server only application - no browser and no client interaction.
I have been reading throuh the various types of authentication the Google APIs support and I am relativelly certain that my usecase maps to the Service Account scenario - so I have been looking at this sample: plus-serviceaccount-cmdline-sample .
Now, I have created a new Application (in the Google APIs console), created Service Account credentials, and generally followed the instructions of the sample. I am however getting:
400 Bad Request
{
"error" : "invalid_grant"
}
Not sure what I am doing wrong - any help is appreciated. Thanks.
The most common way to get an "invalid_grant" error with the service account sample is forgetting to insert the registered email address into your code.
Go to https://developers.google.com/console , then to API Access and look where you registered your service account.
You should see a field labeled that looks like
Email address: XXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXX@developer.gserviceaccount.com
You need to copy this value and insert it into
plus-serviceaccount-cmdline-sample/src/main/java/com/google/api/services/samples/plus/serviceaccount/cmdline/PlusServiceAccountSample.java
In the line as follows:
/** E-mail address of the service account. */
private static final String SERVICE_ACCOUNT_EMAIL = "Enter service account e-mail from "
+ "https://code.google.com/apis/console/?api=plus into SERVICE_ACCOUNT_EMAIL in "
+ PlusServiceAccountSample.class;
So that it looks like this:
/** E-mail address of the service account. */
private static final String SERVICE_ACCOUNT_EMAIL = "XXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXX@developer.gserviceaccount.com";
This, and downloading the .p12 key into the project are crucial for the application to authenticate.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.