Google 日历与 Google App Engine 集成
Google Calendar Integration with Google App Engine
我在 Google 帐户 A 上设置了 Google App Engine 服务和 运行。我希望能够在我的企业 Google 日历帐户 B。我按照 this 作为一般指南。以下是我为此所做的步骤(注意:AppEngine 已经 运行 并且可以正常工作。
- 在我的项目中为 Google 帐户 A
启用了日历 API
- 转到我的帐户 B 的 admin console 并转到安全 -> 高级设置 -> 管理 API 客户端访问并将范围
https://www.googleapis.com/auth/calendar
授权到我的服务 ID帐户 A 中的 App Engine
- Go 中的以下代码
注意:在 getCalendarService
中,我使用 ADC following this repo's 自述文件
获取凭据
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)
}
当我查看日志和错误报告时,没有错误,并且日志显示此消息:
Event created: a Calendar URL
但是当我复制 link 并转到我的 Google 帐户 B 并加载它时,Google 日历显示 "Could not find the requested event"。值得一提的是,如果我将 url 加载到帐户 A 中,它会显示相同的内容。
由于某种原因没有错误,但事件不起作用。我不认为这是我的代码中的问题,而是凭据中的问题,但我可能是错的。
注意:我没有下载任何密钥,我正在使用 ADC 和 App Engine 来获取我的凭据。
如果我没记错的话,
you creating a calendar event with a Service account and insert this
event into the primary calendar OF THE SERVICE ACCOUNT
这可能不是你想要的,相反,如果你想将活动插入你的主日历
- 您需要将此日历的 ID 指定为
calendarId
而不是主要 - 这意味着您事先与服务帐户共享您的日历
- 或者,您使用 impersonation,即构建服务帐户服务,使其充当您(或您域中指定为
ServiceAccountUser
[=21 的其他用户) =]
我在 Google 帐户 A 上设置了 Google App Engine 服务和 运行。我希望能够在我的企业 Google 日历帐户 B。我按照 this 作为一般指南。以下是我为此所做的步骤(注意:AppEngine 已经 运行 并且可以正常工作。
- 在我的项目中为 Google 帐户 A 启用了日历 API
- 转到我的帐户 B 的 admin console 并转到安全 -> 高级设置 -> 管理 API 客户端访问并将范围
https://www.googleapis.com/auth/calendar
授权到我的服务 ID帐户 A 中的 App Engine - Go 中的以下代码
注意:在 getCalendarService
中,我使用 ADC following this repo's 自述文件
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)
}
当我查看日志和错误报告时,没有错误,并且日志显示此消息:
Event created: a Calendar URL
但是当我复制 link 并转到我的 Google 帐户 B 并加载它时,Google 日历显示 "Could not find the requested event"。值得一提的是,如果我将 url 加载到帐户 A 中,它会显示相同的内容。
由于某种原因没有错误,但事件不起作用。我不认为这是我的代码中的问题,而是凭据中的问题,但我可能是错的。
注意:我没有下载任何密钥,我正在使用 ADC 和 App Engine 来获取我的凭据。
如果我没记错的话,
you creating a calendar event with a Service account and insert this event into the primary calendar OF THE SERVICE ACCOUNT
这可能不是你想要的,相反,如果你想将活动插入你的主日历
- 您需要将此日历的 ID 指定为
calendarId
而不是主要 - 这意味着您事先与服务帐户共享您的日历 - 或者,您使用 impersonation,即构建服务帐户服务,使其充当您(或您域中指定为
ServiceAccountUser
[=21 的其他用户) =]