【发布时间】:2016-01-27 09:18:27
【问题描述】:
我正在使用来自https://developers.google.com/google-apps/calendar/v3/reference/events/insert的示例
event = Google::Apis::CalendarV3::Event.new{
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: {
date_time: '2015-05-28T09:00:00-07:00',
time_zone:'America/Los_Angeles',
},
end: {
date_time:'2015-05-28T17:00:00-07:00',
time_zone:'America/Los_Angeles',
}
}
result = service.insert_event(calendar_id, event)
但是,我得到了错误:
wwtlf:~/workspace $ ruby test.rb
/usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/http_command.rb:202:in `check_status': required: Missing end time. (Google::Apis::ClientError)
from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/api_command.rb:103:in `check_status'
from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/http_command.rb:170:in `process_response'
from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/http_command.rb:275:in `execute_once'
from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/http_command.rb:107:in `block (2 levels) in execute'
from /usr/local/rvm/gems/ruby-2.3.0/gems/retriable-2.1.0/lib/retriable.rb:54:in `block in retriable'
from /usr/local/rvm/gems/ruby-2.3.0/gems/retriable-2.1.0/lib/retriable.rb:48:in `times'
from /usr/local/rvm/gems/ruby-2.3.0/gems/retriable-2.1.0/lib/retriable.rb:48:in `retriable'
from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/http_command.rb:104:in `block in execute'
from /usr/local/rvm/gems/ruby-2.3.0/gems/retriable-2.1.0/lib/retriable.rb:54:in `block in retriable'
from /usr/local/rvm/gems/ruby-2.3.0/gems/retriable-2.1.0/lib/retriable.rb:48:in `times'
from /usr/local/rvm/gems/ruby-2.3.0/gems/retriable-2.1.0/lib/retriable.rb:48:in `retriable'
from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/http_command.rb:96:in `execute'
from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/base_service.rb:267:in `execute_or_queue_command'
from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/generated/google/apis/calendar_v3/service.rb:1207:in `insert_event'
示例中的事件对象有什么问题? 我尝试使用 dateTime insted date_time,但错误是一样的。
统一更新: 原始示例:
event = Google::Apis::CalendarV3::Event.new{
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: {
date_time: '2015-05-28T09:00:00-07:00',
time_zone: 'America/Los_Angeles',
},
end: {
date_time: '2015-05-28T17:00:00-07:00',
time_zone: 'America/Los_Angeles',
},
recurrence: [
'RRULE:FREQ=DAILY;COUNT=2'
],
attendees: [
{email: 'lpage@example.com'},
{email: 'sbrin@example.com'},
],
reminders: {
use_default: false,
overrides: [
{method' => 'email', 'minutes: 24 * 60},
{method' => 'popup', 'minutes: 10},
],
},
}
显然,有很多语法错误。 (missed ')method' => 'popup', 'minutes(missed '): 10
所以,我决定修改它:
event = Google::Apis::CalendarV3::Event.new{
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: {
date_time:'2015-05-28T09:00:00-07:00',
time_zone:'America/Los_Angeles',
},
end: {
date_time:'2015-05-28T17:00:00-07:00',
time_zone:'America/Los_Angeles',
},
recurrence: [
'RRULE:FREQ=DAILY;COUNT=2'
],
attendees: [
{email: 'lpage@example.com'},
{email: 'sbrin@example.com'},
],
reminders: {
use_default: false,
overrides: [
{'method' => 'email', 'minutes'=> 24 * 60},
{'method' => 'popup', 'minutes'=> 10},
],
}
}
但是,我仍然得到 http_command.rb:202:in `check_status': required: Missing end time。 (Google::Apis::ClientError)
【问题讨论】:
-
您能否尝试查看(并粘贴到此处)实际的 http 请求是什么以及其中的事件的 JSON 主体是什么?
-
免责声明 - 不是 ruby 开发者。出于某种原因,
end对象未被识别。我看到您的代码 sn-p 类似于sample in the documentation,我看到的唯一不同之处(除了一些属性被删除)是最后一个属性(end),没有以“,”结尾其他对象。如果你检查其他看起来以逗号结尾的对象,你能测试一下吗? -
您可以将“解决方案”从问题主体移到真正的答案——在 SO 回答自己的问题是可以的。
标签: ruby google-calendar-api google-api-ruby-client