【发布时间】:2019-10-22 07:49:44
【问题描述】:
我在我的 Rails 5.2.3 应用中使用 Google Calendar API,并尝试在我的 G Suite 域中的 Google Calendar 上创建事件。我已经能够阅读日历并列出事件。当我尝试插入事件时,我收到错误“requiredAccessLevel: You need to have writer access to this calendar。”
由于这是一个内部应用程序,我在 Google API 控制台中注册了一个服务帐户,并验证该帐户能够读取日历和事件。
在 G Suite 管理控制台中,我已为 https://www.googleapis.com/auth/calendar 和 https://www.googleapis.com/auth/calendar.events 范围的服务帐号授予权限
我在自己的帐户下创建了日历,并添加了具有“更改活动”权限的服务帐户
这是我正在运行的代码示例。
calendar_id = '12345' #obviously not but I've verified that I have the right calendar.
scopes = ['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.events']
authorization = Google::Auth.get_application_default(scopes)
client = Google::Apis::CalendarV3::CalendarService.new
client.authorization = authorization
start_time = Time.current
end_time = Time.current + 2.hours
newEvent = Google::Apis::CalendarV3::Event.new({
summary: "Sample Event",
start: {
date_time: start_time.rfc3339,
time_zone: start_time.strftime("%Z")
},
end: {
date_time: end_time.rfc3339
time_zone: end_time.strftime("%Z")
}
})
result = client.insert_event(calendar_id, newEvent)
我确定我在某处错过了写入权限,但我不明白为什么我会得到“requiredAccessLevel:您需要拥有此日历的写入权限”。而不是插入工作。感谢您的任何建议!
【问题讨论】:
-
谢谢,@Chloe。那解决了它。我已经搜索过,但显然不够长。
标签: ruby-on-rails google-calendar-api