Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Introduction

This document describes how to setup synchronization between a Rails application and Google Calendar. I am using the Google Calendar API v3 with OAuth2 and a service account to programmatically access and manage the calendar data.

Create the service account and its credentials

The service account will do the communication between the application and Google Calendar (through the v3 API). This account will at a later stage be used to impersonate the calendar user (in the same domain), so that all calendar updates appear to come from the calendar user, instead of the service account.

...

Note
titleYou should now have
  • Client ID (xxx.apps.googleusercontent.com)
  • email address (xxx@developer.gserviceaccount.com)
  • A private key file

Share your calendar with the service account

Your service account will need to have access to the Google Calendar of the calendar user, to do this:

  1. Sign in to the account of which you want to share the Google Calendar.
  2. Visit Google Calendar
  3. Click on settings/calendars and 'edit settings' of the calendar you want to share
  4. In the field 'Share with specific people' add the developer email address: xxxxxx@developer.gserviceaccount.com
  5. select proper permissions and click on save.

Delegate domain-wide authority to your service account

If you skip this step, all events created by your service account will show the service accounts email address as the creator. To fix this, it needs to be granted access to the Google Apps domain’s user data that you want to access. The following tasks have to be performed by an administrator of the Google Apps domain:

  1. Go to your Google Apps domain’s Admin console.
  2. Select Security from the list of controls. If you don't see Security listed, select More controls from the gray bar at the bottom of the page, then select Security from the list of controls.
  3. Select Advanced settings from the list of options.
  4. Select Manage third party OAuth Client access in the Authentication section.
  5. In the Client name field enter the service account's Client ID.
  6. In the One or More API Scopes field enter the list of scopes that your application should be granted access to (https://www.googleapis.com/auth/calendar)
  7. Click the Authorize button.

Setup your rails environment

  1. Install gem 'google-api-client'
  2. Copy private key to your local folder and set proper permissions
  3. In your ruby code, the parameters you pass should contain calendarId (primary) and person (the email address of the calendar user)
  4. See EventR for a working code sample

...