我已经在Google帐户A上设置并运行了Google App Engine服务。我想做的是在我公司的Google日历帐户B上预订活动。我遵循此作为一般指南。这是我执行此操作的步骤(注意:AppEngine已在运行并且可以正常运行。
https://www.googleapis.com/auth/calendar
为我在帐户A中的App Engine的服务ID 授权范围。注意:在中getCalendarService
,我按照此仓库的 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)
}
当我查看日志和错误报告时,没有错误,并且日志显示此消息:
活动已创建:日历网址
但是当我复制链接并转到我的Google帐户B并加载该链接时,Google日历会显示“找不到所请求的事件”。值得一提的是,如果我将网址加载到帐户A中,则说明的是同一件事。
由于某种原因,没有错误,但是该事件不起作用。我认为这不是我的代码中的问题,但不是凭据中的问题,但是我可能是错的。
注意:我没有下载任何密钥,而是将ADC与App Engine一起使用来获取我的凭据。
如果我没有记错的话,
您使用服务帐户创建日历事件并将此事件插入到服务帐户的主日历中
相反,如果您想将事件插入主日历,则可能不是您想要的
calendarId
而不是主日历-这意味着您需要事先与服务帐户共享日历ServiceAccountUser
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句