Sync Google Calendar With Org Agenda

I use org-mode an awful lot - it helps me manage my tasks and code all in one place.


However, the organisation that I work for have just migrated over to Google Suite and manage meetings extensively using Google Calendar. I really wanted my Google Calendar to sync with my org-agenda. Org-agenda is a tool that pulls in any scheduled activities from all your files in to one dynamic view. It’s pretty much what drives my working day. Having meetings arranged with colleagues in my org-agenda will help me schedule my day.

The package org-gcal provides two way syncing with Google Calendar (and has other documentation).

This is how I did it.

Install org-cal

Using elpa, I installed the package:

M-x package-list

Highlight the org-gcal package and install.

Create Api Credentials

Then, go to google and get credentials to access your calendar. You will need to go to the google developers portal where you may need to enable the developers’ api. You will need to find Api & Services and then click on credentials. You will create some OAuth 2.0 client IDs credentials - one being the API key and the other being a secret. Make a note of these, or download the JSON file that Google provides.

Screenshot-2018-3-23 Credentials - org-gcal

Enable these credentials for Google Calendar.

Screenshot-2018-3-23 APIs Services - org-gcal

Identify Calendar

Then, the README for org-cal tells you to find the link for your calendar. This didn’t work for me. Instead, I found the link in the url in the address bar of my browser (click on the image to see more detail):


Create settings

(require ‘org-gcal) (setq org-gcal-client-id “your-id-foo.apps.googleusercontent.com” org-gcal-client-secret “your-secret” org-gcal-file-alist ‘((“your-mail@gmail.com” . “~/schedule.org”) (“another-mail@gmail.com” . “~/task.org”)))

Copy that string in to your ~.emacs file, substituting the proper parts (your org-gcal-client-id and secret and the files that you wish to create when you sync).

Save the file and then execute M-x load-file <RET>.emacs to reload this file.

Sync and org-agenda-file-to-front

Now you need to sync your calendar, which will create a new org file (as you specified in the settings.

M-x org-gcal-sync

Once that file is created open it C-x C-f </path/to/file> and thenM-x org-agenda-file-to-front`. This command will include the new file.

You can also create a hook to run org-gcal-sync when you open your agenda by placing this snippet in your .emacs file:

(add-hook 'org-agenda-mode-hook (lambda () (org-gcal-sync) ))