【发布时间】:2020-02-13 01:59:27
【问题描述】:
我在 Google 帐户 A 上设置并运行了 Google App Engine 服务。我想做的是在我公司的 Google 日历帐户 B 上预订活动。我按照this 作为一般指南。以下是我为此执行的步骤(注意:AppEngine 已经在运行并且可以正常工作。
- 在我的项目中为 Google 帐户 A 启用日历 API
- 转到我的帐户 B 的 admin console 并转到安全性 -> 高级设置 -> 管理 API 客户端访问,并将范围
https://www.googleapis.com/auth/calendar授权给我在帐户 A 中的 App Engine 的服务 ID。 - Go 中的以下代码
注意:在getCalendarService 中,我使用ADC 在此repo's README 之后获取凭据
func getCalendarService() (*calendar.Service, error) {
ctx := context.Background()
return calendar.NewService(ctx, option.WithScopes(calendar.CalendarScope))
}
// code adapted from https://developers.google.com/calendar/create-events/
func bookEvent() {
srv, err := getCalendarService()
if err != nil {logAndPrintError(err)}
event := &calendar.Event{
Summary: "Test Title",
Description: "Lorem ipsum",
Start: &calendar.EventDateTime{
DateTime: "2020-02-12T09:00:00-07:00",
TimeZone: "America/Chicago",
},
End: &calendar.EventDateTime{
DateTime: "2020-02-12T17:00:00-07:00",
TimeZone: "America/Chicago",
},
}
calendarId := "primary"
event, err = srv.Events.Insert(calendarId, event).Do()
if err != nil {
logAndPrintError(err)
}
log.Printf("Event created: %s\n", event.HtmlLink)
}
当我查看日志和错误报告时,没有错误,并且日志显示以下消息:
已创建事件:日历 URL
但是当我复制链接并转到我的 Google 帐户 B 并加载它时,Google 日历显示“找不到请求的活动”。值得一提的是,如果我将 url 加载到 Account A 中,它会说同样的话。
由于某种原因没有错误,但该事件不起作用。我认为这不是我的代码中的问题,而是凭据中的问题,但我可能是错的。
注意:我没有下载任何密钥,我正在使用 ADC 和 App Engine 来获取我的凭据。
【问题讨论】:
标签: google-app-engine go google-cloud-platform google-calendar-api