我正在嘗試使用 Google 設定域范圍的委派,以便我可以訪問作業區日歷。我已經閱讀了檔案,這是我到目前為止所得到的:
- 已設定應用的服務帳號
- 此帳戶已啟用 Google Calendar API
- 生成并保存的 JSON 密鑰
- 將應用程式的帳戶客戶端 ID 添加到安全性 -> API 控制 -> 具有正確范圍的域范圍委派
應用的服務帳號:

作業區:

這是我用于檢索簡單日歷事件的簡單 Ruby 代碼:
google_calendar_service = ::Google::Apis::CalendarV3::CalendarService.new
google_calendar_service.authorization ::Google::Auth::ServiceAccountCredentials.make_creds(json_key_io: File.open(PATH_TO_JSON_FILE), scope: MY_SCOPES)
google_calendars.get_event(owner_email, event_id)
兩者都是正確的owner_email,event_id因為我有一個使用 OAuth2 的作業代碼,它可以按預期獲取事件。
我錯過了什么?
uj5u.com熱心網友回復:
您需要添加要委派的主題。這需要是您希望服務帳戶代表您的域中的用戶
檢查 authorizer.sub 行。
authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
json_key_io: StringIO.new(File.read AppConfig[:credentials_file]),
scope: AppConfig[:cal_scope]).dup
authorizer.sub = @person
authorizer.fetch_access_token!
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/487398.html
標籤:轨道上的红宝石 红宝石 谷歌API 谷歌日历 API google-api-ruby 客户端
