2
votes

I've got two Service Accounts for executing Calendar API requests. Both were generated by the same way but it is a small difference between them.
E-mail address of first Service Account ends with "@developer.gserviceaccount.com" and it works.
E-mail address of second Service Account ends with "@project-id.iam.gserviceaccount.com" and after executing request to Calendar API I get an error:

{
  "code" : 400,
  "errors" : [ {
    "domain" : "usageLimits",
    "message" : "Bad Request",
    "reason" : "keyInvalid"
  } ],
  "message" : "Bad Request"
}

Code example:

HttpTransport httpTransport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();   

 GoogleCredential credential = new GoogleCredential.Builder()
                        .setTransport(httpTransport)
                        .setJsonFactory(jsonFactory)
                        .setServiceAccountId(service_account_email)
                        .setServiceAccountScopes(Arrays.asList("https://www.googleapis.com/auth/calendar"))
                        .setServiceAccountUser(user_email)
                        .setServiceAccountPrivateKeyFromP12File(
                            new java.io.File("key.p12")).build();

    Calendar service = new Calendar.Builder(httpTransport, jsonFactory,
            credential).setApplicationName("MyApp")
            .build();

    service.events().list("primary").execute();

Any ideas what can be reason of it?

EDIT:
The problem occurs also when I try to use Directory API.

1
You are using the wrong format of SSL handshake - Fred Ondieki
So why one of Service Accounts works? - user

1 Answers

0
votes

It seems that it was temporary problem with new Service Accounts and Google APIs. Now all Service Accounts works.