【发布时间】:2013-11-17 02:49:16
【问题描述】:
我正在使用服务帐户并尝试将事件插入日历。我正在使用红宝石绑定。我经常收到错误
缺少结束时间
即使我正在发送结束时间!
我的插入代码如下所示
event = {start: DateTime.now, end: (DateTime.now + 0.5)}
result = client.execute( api_method: calendar.events.insert,
parameters:{calendarId: 'MYCALENDARID@group.calendar.google.com'},
authorization: client.authorization,
headers: { "Content-Type" => "application/json" },
body: JSON.dump(event))
如您所知,活动有开始和结束日期!基于一些旧的 SO 答案,我也尝试过:
- 将正文粘贴在数组中(如
body: [JSON.dump(event)])导致异常(undefined methodbytesize' for #`) - 改用 body_object 属性(如
body_object: event),同样的问题
作为参考,设置如下:
require 'google/api_client'
require 'google/api_client/client_secrets'
require 'google/api_client/auth/installed_app'
client = Google::APIClient.new(:application_name => 'Example Ruby application',:application_version => '1.0.0')
key = Google::APIClient::KeyUtils.load_from_pkcs12('MYKEY.p12', 'notasecret')
client.authorization = Signet::OAuth2::Client.new(
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',:audience => 'https://accounts.google.com/o/oauth2/token',:scope => 'https://www.googleapis.com/auth/calendar',
issuer: 'MYSERVICEACCOUNT@developer.gserviceaccount.com', signing_key: key)
client.authorization.fetch_access_token!
calendar = client.discovered_api('calendar', 'v3')
【问题讨论】:
标签: ruby google-api google-api-client