【问题标题】:google calendar api (ruby) event insert error: Missing end timegoogle calendar api (ruby) 事件插入错误:缺少结束时间
【发布时间】: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


    【解决方案1】:

    文档 (https://developers.google.com/google-apps/calendar/v3/reference/events/insert) 给出了以下 Ruby 示例:

    event = {
      'summary' => 'Appointment',
      'location' => 'Somewhere',
      'start' => {
        'dateTime' => '2011-06-03T10:00:00.000-07:00'
      },
      'end' => {
        'dateTime' => '2011-06-03T10:25:00.000-07:00'
      },
      'attendees' => [
        {
          'email' => 'attendeeEmail'
        },
        #...
      ]
    }
    result = client.execute(:api_method => service.events.insert,
                            :parameters => {'calendarId' => 'primary'},
                            :body => JSON.dump(event),
                            :headers => {'Content-Type' => 'application/json'})
    print result.data.id
    

    建议您确认输出开始/结束日期时间{start: DateTime.now, ...} 的代码实际上是在创建您需要的嵌套{'start' => {'dateTime' => '2011-....'}, ...}。

    我不了解 Ruby,但我猜{'start' => {'dateTime' => DateTime.now}, ...} 会满足您的需求(开始和结束日期时间)。

    【讨论】:

    • 谢谢,我完全错过了那里的 ruby​​ 选项卡,正在查看与这里无关的 java。
    猜你喜欢
    • 2018-08-13
    • 1970-01-01
    • 2015-07-03
    • 2011-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多