首页 > 解决方案 > 如何解决来自 nylas 的“无法在只读日历上创建事件”的错误?

问题描述

我在我的 Ruby-on-Rails 应用程序中使用 nylas。
我在 nylas 使用谷歌作为我的提供者。我想向谷歌日历添加一个事件。
在谷歌认证后,谷歌返回refresh-token给我。我用它把这封电子邮件添加到 nylas。最后 nylas 给我发了一个access_token.

以下几行是我使用的谷歌范围:

openid
email
profile
https://www.googleapis.com/auth/userinfo.email
https://www.google.com/m8/feeds/
https://www.googleapis.com/auth/userinfo.profile 
https://mail.google.com/  
https://www.googleapis.com/auth/calendar 
https://www.googleapis.com/auth/calendar.events

所以,现在我想使用以下代码段将事件添加到日历中。

nylas = Nylas::API.new(app_id: "My_nylas_app_id",app_secret: "My_nylas_app_secret", access_token: "user_access_token")

calendar = nylas.calendars.first()

nylas.events.create(title: "A fun event!", location: "The Party Zone", calendar_id: calendar.id,when: { start_time: Time.now + 60, end_time: Time.now + 120 }).to_h

并且,上面的代码片段返回以下错误:

D, [2021-05-23T09:49:39.148247 #9070] DEBUG -- : [httplog] Connecting: api.nylas.com:443
D, [2021-05-23T09:49:39.954976 #9070] DEBUG -- : [httplog] Sending: POST http://api.nylas.com:443/events
D, [2021-05-23T09:49:39.955023 #9070] DEBUG -- : [httplog] Data: 
D, [2021-05-23T09:49:39.955071 #9070] DEBUG -- : [httplog] Status: 400
D, [2021-05-23T09:49:39.955096 #9070] DEBUG -- : [httplog] Benchmark: 0.391611 seconds
D, [2021-05-23T09:49:39.955136 #9070] DEBUG -- : [httplog] Response:
{"message":"Can't create events on read_only calendar.","type":"invalid_request_error"}

标签: ruby-on-rails

解决方案


推荐阅读