Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use google-api-ruby-client with the Google Calendar API?
    primarykey
    data
    text
    <p>I've been reading the docs for the Google Calendar API and the google-api-ruby-client library, but I'm having a lot of trouble understanding them.</p> <p>I have a Rails application that has a front end that lets users create objects called Events, and it saves them in a database on my server. What I would like is, after these Events are saved in the database, I want to call the Google Calendar API to create an event on a Google Calendar (that the server created, and only the server has access to modify that calendar). </p> <p>I'm having lots of issues figuring out how to authenticate with the API using the ruby library. It doesn't make sense for me to use OAuth2 because I don't need to authorize anything with the user because I'm not interested in their data. I looked into Service Accounts (http://code.google.com/p/google-api-ruby-client/wiki/ServiceAccounts), but it looks like Google Calendars is not supported by Service Accounts. </p> <p>Anyone have any ideas? This is the code I was experimenting with (using Service Accounts):</p> <pre><code>@client = Google::APIClient.new(:key =&gt; 'my_api_key') path_to_key_file = '/somepath/aaaaaa-privatekey.p12' passphrase = 'my_pass_phrase' key = Google::APIClient::PKCS12.load_key(path_to_key_file, passphrase) asserter = Google::APIClient::JWTAsserter.new( 'blah_blah@developer.gserviceaccount.com', 'https://www.googleapis.com/auth/calendar', key) # To request an access token, call authorize: @client.authorization = asserter.authorize() calendar = @client.discovered_api('calendar', 'v3') event = { 'summary' =&gt; 'Appointment', 'location' =&gt; 'Somewhere', 'start' =&gt; { 'dateTime' =&gt; '2012-06-03T10:00:00.000-07:00' }, 'end' =&gt; { 'dateTime' =&gt; '2012-06-03T10:25:00.000-07:00' }, 'attendees' =&gt; [ { 'email' =&gt; 'attendeeEmail' }, #... ] } result = @client.execute!(:api_method =&gt; calendar.events.insert, :parameters =&gt; {'calendarId' =&gt; 'primary'}, :body =&gt; JSON.dump(event), :headers =&gt; {'Content-Type' =&gt; 'application/json'}) </code></pre> <p>Then of course I get this error message: Google::APIClient::ClientError (The user must be signed up for Google Calendar.) because the Service Account does not support Google Calendars.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload