引用了Google Calendar API with PHP – Service Account并尝试了以下步骤:
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()。表()
返回[],也没有错误。我错过了什么吗?
答案 0 :(得分:2)
对于#1,请尝试在SO post。
中执行此处的建议无论使用何种语言,请尝试与服务帐户共享现有日历。
<paste-your-account-here>@developer.gserviceaccount.com
要了解#2,请尝试按照此SO post中的接受答案进行操作。
转到Google日历网站添加服务帐户电子邮件 作为日历的用户地址。然后服务帐户将是 能够访问它。如果您愿意,可以通过编程方式将其插入 calendar.list如果你真的需要它在那里。
答案 1 :(得分:-1)
请尝试
return calendar.calendarList().list().execute();