Google API,无法为Outlook邀请更新自己的RSVP状态

时间:2018-12-04 10:01:13

标签: ruby-on-rails outlook google-calendar-api

我正在使用Google Calendar API更新我的RSVP状态, 如果它是Google邀请,效果很好,但如果邀请是Outlook,则抛出以下错误

{
"error": {
    "errors": [
        {
            "domain": "calendar",
            "reason": "forbiddenForNonOrganizer",
            "message": "The operation can only be performed by the organizer of the event."
        }
    ],
    "code": 403,
    "message": "The operation can only be performed by the organizer of the event."
    }
}

this是Google api链接,其中“ attendees []。responseStatus”是代表RSVP状态的属性

我正在使用“ Ruby on Rails”,下面是用于更新事件的代码。

def update_event(event)
  auth = set_google_auth(calendar)
  @client.update!(auth)
  service = Google::Apis::CalendarV3::CalendarService.new
  service.authorization = @client
  attendees_array = [
    {
     # This is the authenticated user, where i am trying to update rsvp
     "email": "user_one@gmail.com",
     "responseStatus": "tentative"
    },
    {
     "email": "other_user@gmail.com"
    }
  ]
  google_event = Google::Apis::CalendarV3::Event.new({
    ...,
    'attendees': attendees_array,
    ...
  })
end

和set_google_auth方法

def set_google_auth(calendar)
  auth = Hash.new
  auth["access_token"] = linked_calendar.access_token
  auth["expires_in"] = 3600
  auth["token_type"] = "Bearer"
  return auth
end

正在更新事件的用户当前已通过Google身份验证,即他/她正在更新自己日历的状态。

1 个答案:

答案 0 :(得分:0)

我建议使用补丁程序,并且仅修改与会者状态。否则,您的新事件可能不会包含与原始事件完全相同的值,并且服务器会认为您正在尝试将其修改为与会者而失败。

我已验证此方法适用于API资源管理器中来自Exchange的邀请。

PATCH https://www.googleapis.com/calendar/v3/calendars/primary/events/<event_id>?sendUpdates=all&key={YOUR_API_KEY}

{
 "attendees": [
  {
   "email": "email@email.com",
   "self": true,
   "responseStatus": "tentative"
  }
 ]
}