所以我已经有了这个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(事件,&#39; primary&#39;)时,我收到此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"}
Google日历API的主要文档使用围绕客户端对象的不同设置,该客户端对象与建议制作日历对象的服务帐户文档不匹配。有没有人知道如何做到这一点,即使它是一个非常不同的实现理想情况下,虽然我想知道什么?我希望能够在客户提出交货请求时将东西放在我的日历上。
答案 0 :(得分:3)
事实证明问题主要与事件有关,因为这个设置必须是一个特殊的谷歌对象而不是哈希。以下是使其运行的代码,我在gems / google-api-client-0.9.pre1 / samples / calendar / calendar.rb
中找到了它require 'googleauth'
require 'google/apis/calendar_v3'
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!
emails = ["me@example.com","myboss@example.com"]
# Create an event, adding any emails listed in the command line as attendees
event = Calendar::Event.new(summary: 'A sample event',
location: '1600 Amphitheatre Parkway, Mountain View, CA 94045',
attendees: emails.each { |email| Calendar::EventAttendee.new(email: email) },
start: Calendar::EventDateTime.new(date_time: DateTime.parse('2015-12-31T20:00:00')),
end: Calendar::EventDateTime.new(date_time: DateTime.parse('2016-01-01T02:00:00')))
event = calendar.insert_event('primary', event, send_notifications: true)
puts "Created event '#{event.summary}' (#{event.id})"
end