Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google freebusy api call in rails will not recognizing parameters

I am trying to find all the freebusy times from my primary calendar, but I cannot get the query to recognize my parameters.

In my controller I have:

@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' => '[email protected]'}]
  },
  :headers => {'Content-Type' => 'application/json'})

the response I get is:

 --- !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.

However is shows that it took the parameters, but they did not get attached to the query:

--- !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: [email protected]

Any help solving this would be greatly appreciated!

like image 659
Tristan Toye Avatar asked Jun 18 '13 13:06

Tristan Toye


2 Answers

solved this by specifying the request body

client.execute(
  :api_method => service.freebusy.query,
  :body => JSON.dump({
    :timeMin => ,
    :timeMax => ,
    :items => 
  }),
  :headers => {'Content-Type' => 'application/json'})
like image 153
user3330504 Avatar answered Sep 20 '22 07:09

user3330504


I was having a similar problem. An alternative, is that you can build a FreeBusyRequest object.
Like this:

 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

``` and then you can pass it into a CalendarService object like this:

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

this will definitely return a status 200 response with a body.

like image 40
Arnold_Sanders Avatar answered Sep 19 '22 07:09

Arnold_Sanders