authorize google calendar api works on personal account but not on google domain account

萝らか妹 提交于 2019-11-29 12:38:40

To have access to all accounts in the domain, you need to use a service account:

https://developers.google.com/accounts/docs/OAuth2ServiceAccount

while this link is specific to Drive API, it should give you some code samples that are easily adaptable to Calendar API v3:

https://developers.google.com/drive/delegation

Stephan Celis

For future reference I used the following code for the authorizing the Google Calendar

   java.io.File licenseFile = new java.io.File("39790cb51b361f51cab6940d165c6cda4dc60177-privatekey.p12");

   GoogleCredential credential = new GoogleCredential.Builder()

  .setTransport(HTTP_TRANSPORT)
  .setJsonFactory(JSON_FACTORY)
  .setServiceAccountId("xxxxx@developer.gserviceaccount.com")   

  .setServiceAccountUser("USER_EMAIL_ADRESS")
  .setServiceAccountScopes(CalendarScopes.CALENDAR)
  .setServiceAccountPrivateKeyFromP12File(licenseFile)
  .build();

  client = new com.google.api.services.calendar.Calendar.Builder(
                        HTTP_TRANSPORT, JSON_FACTORY, credential)
                        .setApplicationName( "Google Calendar Sync").build();

Also these links helped a lot about setting up a Service account:

OAuth Google API for Java unable to impersonate user

Can a Google Apps Admin manage users files with Drive SDK?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!