使用 Google 日历 API 检索域内的所有事件
retrieve all events within a domain using Google Calendar API
我正在尝试使用 Google 日历 API.
检索在域 entreprise.tn
中编排的所有事件
在 google 管理控制台上,我创建了一个新项目和一个具有 owner
角色的新服务帐户,如 that thread 所述。
我启用了 Google 日历 API 和 Admin SDK,如 that thread 所述。
在管理控制台>安全上添加的范围列表是:
https://www.googleapis.com/auth/admin.directory.user, https://www.googleapis.com/auth/admin.directory.group, https://www.googleapis.com/auth/admin.directory.resource.calendar, https://www.googleapis.com/auth/calendar.events.readonly, https://www.googleapis.com/auth/calendar.readonly
我的代码是:
Calendar service = getCalendarService();
List<Event> items = new ArrayList<Event>();
String pageToken = null;
do
{
Events events = service.events().list("service-account-esp1@my-first-project-274515.iam.gserviceaccount.com").setPageToken(pageToken).execute();
items = events.getItems();
for (Event event : items)
{
System.out.println(event.getSummary());
}
pageToken = events.getNextPageToken();
} while (pageToken != null);
if (items.isEmpty())
{
System.out.println("Empty");
}
else
{
System.out.println("Exists");
}
文件my-first-project-274515-361633451f1c.json
是在创建服务帐户和执行 G Suite 全域授权时生成的文件。
service-account-esp1@my-first-project-274515.iam.gserviceaccount.com
是 客户邮箱
看起来不错,所有需要的配置都已完成。
无论如何,我得到了那个例外:
avr. 18, 2020 12:28:59 PM
com.google.api.client.util.store.FileDataStoreFactory
setPermissionsToOwnerOnly AVERTISSEMENT: Unable to set permissions for
C:\Users\Administrateur\credentials, because you are running on a
non-POSIX file system. Charge Calendars: Sat Apr 18 12:28:59 BST 2020
a Exception in thread "main" java.lang.IllegalArgumentException at
com.google.common.base.Preconditions.checkArgument(Preconditions.java:128)
at
com.google.api.client.util.Preconditions.checkArgument(Preconditions.java:35)
at
com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets.getDetails(GoogleClientSecrets.java:82)
at
com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow$Builder.(GoogleAuthorizationCodeFlow.java:197)
at
tn.esprit.spring.google.calendar.Service.getCredentials(Service.java:75)
at
tn.esprit.spring.google.calendar.Service.getCalendarService(Service.java:90)
at tn.esprit.spring.google.calendar.Service.main(Test.java:102)
已在 GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES).setDataStoreFactory(DATA_STORE_FACTORY).setAccessType("offline").build();
上屏蔽
你能告诉我我错过了什么吗?。
提前致谢。
您应该改用邮件用户:
Events events = service.events().list(user@entreprise.tn)
.setOrderBy("startTime")
.setSingleEvents(true)
.execute();
HTH
我正在尝试使用 Google 日历 API.
检索在域entreprise.tn
中编排的所有事件
在 google 管理控制台上,我创建了一个新项目和一个具有 owner
角色的新服务帐户,如 that thread 所述。
我启用了 Google 日历 API 和 Admin SDK,如 that thread 所述。
在管理控制台>安全上添加的范围列表是: https://www.googleapis.com/auth/admin.directory.user, https://www.googleapis.com/auth/admin.directory.group, https://www.googleapis.com/auth/admin.directory.resource.calendar, https://www.googleapis.com/auth/calendar.events.readonly, https://www.googleapis.com/auth/calendar.readonly
我的代码是:
Calendar service = getCalendarService();
List<Event> items = new ArrayList<Event>();
String pageToken = null;
do
{
Events events = service.events().list("service-account-esp1@my-first-project-274515.iam.gserviceaccount.com").setPageToken(pageToken).execute();
items = events.getItems();
for (Event event : items)
{
System.out.println(event.getSummary());
}
pageToken = events.getNextPageToken();
} while (pageToken != null);
if (items.isEmpty())
{
System.out.println("Empty");
}
else
{
System.out.println("Exists");
}
文件my-first-project-274515-361633451f1c.json
是在创建服务帐户和执行 G Suite 全域授权时生成的文件。
service-account-esp1@my-first-project-274515.iam.gserviceaccount.com
是 客户邮箱
看起来不错,所有需要的配置都已完成。 无论如何,我得到了那个例外:
avr. 18, 2020 12:28:59 PM com.google.api.client.util.store.FileDataStoreFactory setPermissionsToOwnerOnly AVERTISSEMENT: Unable to set permissions for C:\Users\Administrateur\credentials, because you are running on a non-POSIX file system. Charge Calendars: Sat Apr 18 12:28:59 BST 2020 a Exception in thread "main" java.lang.IllegalArgumentException at com.google.common.base.Preconditions.checkArgument(Preconditions.java:128) at com.google.api.client.util.Preconditions.checkArgument(Preconditions.java:35) at com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets.getDetails(GoogleClientSecrets.java:82) at com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow$Builder.(GoogleAuthorizationCodeFlow.java:197) at tn.esprit.spring.google.calendar.Service.getCredentials(Service.java:75) at tn.esprit.spring.google.calendar.Service.getCalendarService(Service.java:90) at tn.esprit.spring.google.calendar.Service.main(Test.java:102)
已在 GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES).setDataStoreFactory(DATA_STORE_FACTORY).setAccessType("offline").build();
你能告诉我我错过了什么吗?。 提前致谢。
您应该改用邮件用户:
Events events = service.events().list(user@entreprise.tn)
.setOrderBy("startTime")
.setSingleEvents(true)
.execute();
HTH