我在 Google 帐户 A 上设置并运行了 Google App Engine 服务。我想做的是在我的企业的 Google 日历帐户 B 上预订活动。我将此作为一般指南。以下是我为此执行的步骤(注意:AppEngine 已经在运行并且可以正常工作。
在我的项目中为 Google 帐户 A 启用日历 API
转到我帐户 B 的管理控制台,然后转到安全性 -> 高级设置 -> 管理 API 客户端访问权限,并将范围授权https://www.googleapis.com/auth/calendar
给我的帐户 A 中我的 App Engine 的服务 ID。
Go中的以下代码
注意:在 中getCalendarService
,我在这个repo 的README之后使用ADC获取凭据
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 中,它会说同样的事情。
由于某种原因没有错误,但该事件不起作用。我认为这不是我的代码中的问题,而是凭据中的问题,但我可能是错的。
慕姐4208626
相关分类