所以我让这个 Ruby on rails 应用程序运行起来,我设置了一个服务帐户来执行服务器到服务器对谷歌日历 API 的请求。我有日历对象,它的方法包括 insert_event。
class CalendarController < ApplicationController
require 'googleauth'
require 'google/apis/calendar_v3'
def create_event
calendar = Google::Apis::CalendarV3::CalendarService.new
scopes = ['https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/drive']
calendar.authorization = Google::Auth.get_application_default(scopes)
token = calendar.authorization.fetch_access_token!
event = {
'summary' => 'Google I/O 2015',
'location' => '800 Howard St., San Francisco, CA 94103',
'description' => 'A chance to hear more about Google\'s developer products.',
'start' => {
'dateTime' => '2015-05-28T09:00:00-07:00',
'timeZone' => 'America/Los_Angeles',
},
'end' => {
'dateTime' => '2015-05-28T17:00:00-07:00',
'timeZone' => 'America/Los_Angeles',
},
'recurrence' => [
'RRULE:FREQ=DAILY;COUNT=2'
],
'attendees' => [
{'email' => 'myemail1@gmail.com'},
{'email' => 'jdong8@gmail.com'},
],
'reminders' => {
'useDefault' => false,
'overrides' => [
{'method' => 'email', 'minutes' => 24 * 60},
{'method' => 'popup', 'minutes' => 10},
],
},
}
calendar.insert_event(event, 'primary')
end
end
当我尝试运行 calendar.insert_event(event, 'primary') 我得到这个 404 错误
404 (165 bytes) 338ms>
{"domain"=>"global", "reason"=>"notFound", "message"=>"Not Found"}
Caught error {"domain"=>"global", "reason"=>"notFound", "message"=>"Not Found"}
Error - #<Google::Apis::ClientError: {"domain"=>"global", "reason"=>"notFound", "message"=>"Not Found"}>
Google::Apis::ClientError: {"domain"=>"global", "reason"=>"notFound", "message"=>"Not Found"}
谷歌日历 API 的主要文档围绕客户端对象使用不同的设置,该设置与建议制作日历对象的服务帐户文档不匹配。有没有人知道如何做到这一点,即使它是一个非常不同的实现理想情况下我想知道是什么?每当客户提出交货请求时,我希望能够将东西放在我的日历上。