【问题标题】:Google Calendar API: "You need to have writer access to this calendar."谷歌日历 API:“你需要有这个日历的作者权限。”
【发布时间】: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/calendarhttps://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:您需要拥有此日历的写入权限”。而不是插入工作。感谢您的任何建议!

【问题讨论】:

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


【解决方案1】:

感谢上面评论中的 Chloe。解决方案是将前 5 行更改为

scopes = ['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.events']
authorization = Google::Auth.get_application_default(scopes)

auth_client = authorization.dup
auth_client.sub = 'account@mydomain.com'
auth_client.fetch_access_token!

client = Google::Apis::CalendarV3::CalendarService.new
client.authorization = auth_client

【讨论】:

    猜你喜欢
    • 2016-04-01
    • 1970-01-01
    • 2017-03-13
    • 1970-01-01
    • 2011-04-27
    • 1970-01-01
    • 2016-04-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多