【发布时间】:2017-12-05 12:49:48
【问题描述】:
引用Google Calendar API with PHP – Service Account并尝试了以下步骤:
- 在 Google API 控制台中创建了一个项目并在该项目上启用了 Google Calendar API
- 在项目下创建服务账号,下载JWT格式密钥
- 尝试将我的个人日历分享给服务帐号邮箱,不知道是UI bug还是不允许,没有错误,刷新页面后,服务帐号邮箱不见了。我必须使用我公司的 Google 帐户日历,并且可以添加服务帐户。
- 编写 Java 代码以使用第 2 步中的 JWT 密钥来获取日历列表。
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
// Build service account credential.
GoogleCredential credential = GoogleCredential .fromStream(this.getClass().getClassLoader().getResourceAsStream("makoto-c14c149ef994.json")).createScoped(Collections.singleton(CalendarScopes.CALENDAR));
Calendar calendar = new Calendar.Builder(httpTransport, jsonFactory, credential).setApplicationName("makoto").build();
return calendar.calendarList().list();
问题/疑问是:
- 没有列出任何内容
calendar.calendarList().list()
返回[],也没有错误。我错过了什么吗?
- 为什么我不能与服务帐户共享我的个人日历。这仅适用于企业 google 帐户吗?
【问题讨论】: