1

I am playing around with Google calendar API and came across this:

Google Calendar V3 Insert

The Ruby code doesn't seem to be Ruby code so I ported information from the calendar_list and calendar.get to this. I'm not sure why the parameter summary is not being picked up as a title.

def create      
  @auth = request.env["omniauth.auth"]
  @token = @auth["credentials"]["token"]
  client = Google::APIClient.new
  client.authorization.access_token = @token
  service = client.discovered_api('calendar', 'v3')
  @result = client.execute(
    :api_method => service.calendars.insert,
    :parameters => {"summary" => 'Calendar Title'},
    :headers => {'Content-Type' => 'application/json'})
end

Which results in an error of

--- !ruby/object:Google::APIClient::Schema::Calendar::V3::Calendar
data:
  error:
    errors:
    - domain: global
      reason: required
      message: Missing title.
    code: 400
    message: Missing title.
1dolinski
  • 479
  • 3
  • 9
  • 29

1 Answers1

3

Honestly I haven't tried the google api with ruby, but in looking at your error and the google documentation I believe that summary is equal to title (as you stated).

Also, in looking at other examples of inserts (maybe not calendar) I notice that the API can take a :body attribute which probably (in your case) contain the actual calendar data (i.e., "summary"). And here it actually mentions request "body" under tryit.

So again, I haven't tried this but I would try something like the following:

  @result = client.execute(
    :api_method => service.calendars.insert,
    :parameters => # not sure what parameters the insert needs,
    :body => JSON.dump(cal), # where cal is the object containing at least "summary".
    :headers => {'Content-Type' => 'application/json'})
Community
  • 1
  • 1
Arthur Frankel
  • 4,695
  • 6
  • 35
  • 56
  • Thanks Arthur. For anyone else I put the parameters as {} and did JSON.dump('summary' => 'test name'), which generated a test name calendar on my gcal – 1dolinski Sep 01 '13 at 04:48