我在 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 中,它會說同樣的事情。由于某種原因沒有錯誤,但該事件不起作用。我認為這不是我的代碼中的問題,而是憑據中的問題,但我可能是錯的。
1 回答

慕姐4208626
TA貢獻1852條經驗 獲得超7個贊
如果我沒有記錯的話,
您使用服務帳戶創建日歷事件并將此事件插入到服務帳戶的主日歷中
這可能不是您想要的,相反,如果您想將事件插入到您的主日歷中
您需要將此日歷的 id 指定為
calendarId
而不是主要的 - 這意味著您事先與服務帳戶共享您的日歷或者,您使用impersonation,即構建服務帳戶服務,使其充當您(或您的域的另一個用戶指定為
ServiceAccountUser
- 1 回答
- 0 關注
- 112 瀏覽
添加回答
舉報
0/150
提交
取消