Google Calendar API:“您需要对此日历具有作者访问权." [英] Google Calendar API: "You need to have writer access to this calendar."

查看:65
本文介绍了Google Calendar API:“您需要对此日历具有作者访问权."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Rails 5.2.3应用程序中使用Google Calendar API,并试图在我的G Suite域中的Google Calendar上创建事件.我已经能够读取日历和列出事件.尝试插入事件时,出现错误"requiredAccessLevel:您需要对此日历具有作者访问权."

I'm using the Google Calendar API in my Rails 5.2.3 app and trying to create events on a Google Calendar within my G Suite domain. I'm already able to read the calendar and list events. When I try to insert an event, I get the error "requiredAccessLevel: You need to have writer access to this calendar."

因为这是针对内部应用程序的,所以我已经在Google API控制台中注册了一个服务帐户,并已验证该帐户能够读取日历和事件.

As this is for an internal application, I have registered a service account in the Google API console and have verified that the account is able to read calendars and events.

在G Suite管理控制台中,我为服务帐户授予了范围 https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/calendar.events

In the G Suite Admin Console, I've given the service account permissions for the scopes https://www.googleapis.com/auth/calendar and https://www.googleapis.com/auth/calendar.events

我在自己的帐户下创建了日历,并添加了具有对事件进行更改"权限的服务帐户

I created the calendar itself under my account and have added the service account with "Make changes to events" permissions

这是我正在运行的代码的示例.

This is a sample of the code I'm running.

    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:您需要对此日历具有写者访问权限".而不是插入工作.感谢您的任何建议!

I'm sure I've missed a permission somewhere for write access, but haven't figured out why I get "requiredAccessLevel: You need to have writer access to this calendar." instead of the insert working. Thanks for any suggestions!

推荐答案

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

Thanks to Chloe in the comment above. The solution was to change the first 5 lines to to

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

这篇关于Google Calendar API:“您需要对此日历具有作者访问权."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆