5

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

在我的控制器中,我有:

@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

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

4

2 回答 2

7

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

client.execute(
  :api_method => service.freebusy.query,
  :body => JSON.dump({
    :timeMin => ,
    :timeMax => ,
    :items => 
  }),
  :headers => {'Content-Type' => 'application/json'})
于 2014-04-19T19:06:40.760 回答
3

我遇到了类似的问题。另一种选择是您可以构建一个 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 响应。

于 2016-06-29T04:55:06.547 回答