收到错误消息,我需要让作者访问此日历。 (Google::Apis::ClientError)

问题描述 投票:0回答:1

已解决

对 Google Workspace 日历共享设置的更改大约需要 2 小时才能生效。

修复是与服务帐户共享日历并授予其管理事件的权限。

尝试通过脚本创建事件时,我不断收到“您需要拥有此日历的作者访问权限。(Google::Apis::ClientError)”错误。

我已完成并确保以下事项:

  • 服务帐号在 Google Workspace 中具有全域访问权限
  • 确认它也有正确的授权访问(
  • 服务帐户在 Google Cloud 上具有“编辑”角色和权限
  • 允许外部电子邮件共享日历的 Google Workspace 设置

我目前不知所措,希望得到任何建议。

代码如下:

OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'
CREDENTIALS_PATH = File.join(File.dirname(__FILE__), 'credentials.json')
SCOPE = Google::Apis::CalendarV3::AUTH_CALENDAR_EVENTS
APPLICATION_NAME = "GCAL Events"


def authorize
    credentials = Google::Auth::ServiceAccountCredentials.make_creds(
      json_key_io: File.open(CREDENTIALS_PATH),
      scope: SCOPE
    )
    credentials.fetch_access_token!
    credentials
    
  end


  def create_event(summary, start_time, end_time)
    service = Google::Apis::CalendarV3::CalendarService.new
    service.client_options.application_name = APPLICATION_NAME
    service.authorization = authorize
  
    event = Google::Apis::CalendarV3::Event.new({
      summary: summary,
      start: {
        date_time: start_time,
        time_zone: 'Pacific/Auckland'
      },
      end: {
        date_time: end_time,
        time_zone: 'Pacific/Auckland'
      }
    })
  
    
    result = service.insert_event('[email protected]', event)
    puts "Event created: #{result.html_link}"
  end

  
  create_event('xyz', '2023-03-03T09:00:00+12:00', '2023-03-03T10:00:00+12:00')

在 Google Workspace 中的其他用户的日历上创建活动

ruby google-api google-calendar-api
1个回答
0
投票

您需要告诉服务帐户要委托域中的哪个用户。

authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
  json_key_io: StringIO.new(File.read AppConfig[:credentials_file]),
  scope: AppConfig[:cal_scope]).dup
authorizer.sub = @person
authorizer.fetch_access_token!
© www.soinside.com 2019 - 2024. All rights reserved.