【问题标题】:Google freebusy api call in rails will not recognizing parametersRails 中的 Google freebusy api 调用将无法识别参数
【发布时间】:2013-06-14 18:02:28
【问题描述】:

我正在尝试从我的主日历中查找所有空闲时间,但我无法让查询识别我的参数。

在我的控制器中,我有:

@freetimes = client.execute(
  :api_method => service.freebusy.query,
  :parameters => {
  'timeMin' => '2013-06-15T17:06:02.000Z',
  'timeMax' => '2013-06-29T17:06:02.000Z',
  'items' => [{'id' => 'myemail@gmail.com'}]
  },
  :headers => {'Content-Type' => 'application/json'})

我得到的回应是:

 --- !ruby/object:Google::APIClient::Schema::Calendar::V3::FreeBusyResponse
data:
error:
    errors:
    - domain: global
      reason: required
      message: Missing timeMin parameter.
    code: 400
    message: Missing timeMin parameter.

但是显示它接受了参数,但它们没有附加到查询中:

--- !ruby/object:Google::APIClient::Result
request: !ruby/object:Google::APIClient::Request
  parameters:
  timeMin: '2013-06-15T17:06:02.000Z'
  timeMax: '2013-06-29T17:06:02.000Z'
  items:
   - id: myemail@gmail.com

任何解决此问题的帮助将不胜感激!

【问题讨论】:

标签: ruby-on-rails ruby-on-rails-3 api google-calendar-api


【解决方案1】:

通过指定请求正文解决了这个问题

client.execute(
  :api_method => service.freebusy.query,
  :body => JSON.dump({
    :timeMin => ,
    :timeMax => ,
    :items => 
  }),
  :headers => {'Content-Type' => 'application/json'})

【讨论】:

    【解决方案2】:

    我遇到了类似的问题。另一种选择是您可以构建一个 FreeBusyRequest 对象。
    像这样:

     body = Google::Apis::CalendarV3::FreeBusyRequest.new 
     body.items = [calendar_id]
     body.time_min = "2016-06-29T13:00:00z"
     body.time_max = "2016-06-29T21:00:00z"
     body
    

    ``` 然后你可以像这样将它传递给 CalendarService 对象:

    service = Google::Apis::CalendarV3::CalendarService.new
    service.authorization = client
    service.query_freebusy(body)
    

    这肯定会返回带有正文的状态 200 响应。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-29
      • 2017-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多