Google Workspace日历脚本创建事件权限错误排查及解决
在Google Workspace中为其他用户创建日历事件
已解决
Google Workspace日历共享设置的更改大约需要2小时生效。
解决方案是将日历共享给服务账号,并授予其管理事件的权限。
我尝试通过脚本创建事件时,持续收到**"You need to have writer access to this calendar. (Google::Apis::ClientError)"**错误。
已完成并确认以下配置:
- 服务账号在Google Workspace中拥有域级访问权限
- 已确认其具备正确的授权访问权限
- 服务账号在Google Cloud中拥有“Editor”角色和权限
- 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@mydomain.com', 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')
内容的提问来源于stack exchange,提问作者Muffinsnz
相关产品推荐
相关产品推荐

