So basically my Java app is creating one or few Google calendars for each of our Google domain users.
To overcome calendar creation limits (25 cals per few hours or so) I implemented Service Account that is impersonating each of said users. Said service account has API access defined in admin console.
I have created all of those calendars successfully by setting:
.setServiceAccountUser("username@ourdomain.com").
But now I need to create a calendar for each group. If I try to impersonate a group user (.setServiceAccountUser("groupname@ourdomain.com")), I get such error:
400 Bad Request
{
"error" : "access_denied",
"error_description" : "Requested scopes not allowed:
https://www.googleapis.com/auth/calendar
https://www.googleapis.com/auth/calendar.readonly"
}
Relevant code:
private static HttpTransport httpTransport;
private static final String SERVICE_ACCOUNT_EMAIL = "serviceaccountetcetera@developer.gserviceaccount.com";
private static final String SERVICE_ACCOUNT_PKCS12_FILE_PATH = "path\to.p12";
JacksonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
.setServiceAccountScopes(CalendarScopes.all())
.setServiceAccountPrivateKeyFromP12File(new java.io.File(
SERVICE_ACCOUNT_PKCS12_FILE_PATH))
.setServiceAccountUser("groupname@ourdomain.com")
.build();
client = new com.google.api.services.calendar.Calendar.Builder(httpTransport,
JSON_FACTORY, credential).setApplicationName(
APPLICATION_NAME).build();
Calendar entry = new Calendar();
entry.setSummary("summary");
Calendar result = client.calendars().insert(entry).execute();
Why can't I impersonate group username to create a group calendar? How do I create a few hundred group calendars in some other way?
Google support says that it is not possible to impersonate group user.
I have to create calendar by impersonating some group user and share it with a group.