Google Calendar与Google App Engine集成

加布:

我已经在Google帐户A上设置并运行了Google App Engine服务。我想做的是在我公司的Google日历帐户B上预订活动。我遵循作为一般指南。这是我执行此操作的步骤(注意:AppEngine已在运行并且可以正常运行。

  1. 在我的项目中为Google帐户A启用了Calendar API
  2. 转到我的帐户B的管理控制台,然后转到“安全”->“高级设置”->“管理API客户端”访问权限,并https://www.googleapis.com/auth/calendar为我在帐户A中的App Engine的服务ID 授权范围
  3. Go中的以下代码

注意:在中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一起使用来获取我的凭据。

ziganotschka:

如果我没有记错的话,

您使用服务帐户创建日历事件并将此事件插入到服务帐户的主日历中

相反,如果您想将事件插入主日历,则可能不是您想要的

  • 您需要指定此日历的ID calendarId而不是主日历-这意味着您需要事先与服务帐户共享日历
  • 或者,您使用模拟,即以您(或您网域中的另一个用户指定为)的方式构建服务帐户服务ServiceAccountUser

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章