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.
- Sign in to the account of which you want to share the Google Calendar.
- Visit the Google Developers Console
- Set up your project if you haven't already done so and enable the 'Google Calendar API'.
- Select your project and go to "APIs & auth", make sure "Google Calender API" is enabled.
- Click on 'credentials'.
- Click on "Create new client ID". Specify that your application type is service account, and proceed with the setup of the service account
You 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
Delegate domain-wide authority to your service account
- Install gem 'google-api-client'
- Copy private key to your local folder and set proper permissions
- In your ruby code, the parameters you pass should contain calendarId (primary) and person (the email address of the calendar user)
- See EventR for a working code sample