Emacs sync w/ Google Calendar and Contacts?

Unfortunately, I am unable to give a complete answer. All I have is advice about some possible paths to wander down.

The easiest route would be if the emacs-g-client that Gilles mentioned in the SU version of this question works. If that doesn't work, I would look into the following:

  • At the very least you should be able to get some calendar functionality by accessing your google calendar using ical. The function icalendar-import-file can import an ical file to a emacs diary file (icalendar-import-file documentation). Thus, in your .emacs file you could have a bit of emacs lisp to get the google calendar ical file and import it into your diary. If you do end up using org-mode there are a number of ways to integrate org-mode with diary-mode.

  • I think that the ultimate goal would be to make use of the gdata api. I don't think that there is an easy way to get access to Google contacts outside of this api. There is a command line utility that supports a wide range of functionality using this api called Google CL, which could theoretically be used inside some emacs lisp functions to provide full access to your contacts, calendar, and many other Google-hosted services. This however, would likely be much more difficult than just a few lines thrown into your .emacs.


For Google Calendar, I have a one way sync setup successfully. Emacs fetches my calendars at startup and transfers it in the emacs diary. This is then displayed by org-mode in the agenda, but you can set it up anyway you want.

For sending back to Google Calendar, I have yet setup anything as I don't need it that much. However, I think it would be pretty easy to have a function that adds an entry in the diary and calls googlecl to add an entry in your google calendar.

To fetch the calendars, I have the following in my .emacs (not that this is not my code, it comes from the org-mode mailing list, but I can't remember where I found it exactly):

(setq mark-diary-entries-in-calendar t)
(defun getcal (url)
  "Download ics file and add to diary"
  (let ((tmpfile (url-file-local-copy url)))
    (icalendar-import-file tmpfile "~/diary" t)
    (kill-buffer (car (last (split-string tmpfile "/"))))
    )
  )
(setq google-calendars '(
                         "http://www.google.com/calendar/ical/DFSDFSDFSDFASD/basic.ics"
                         "http://www.google.com/calendar/ical/SDFSADFSADFASD/basic.ics"
                         ))
(defun getcals ()
  (interactive)
  (find-file "~/diary")
  (flush-lines "^[& ]")
  (dolist (url google-calendars) (getcal url))
  (kill-buffer "diary"))

Replace "http://www.google.com/calendar/ical/DFSDFSDFSDFASD/basic.ics" with the urls to the calendars you want to fetch (you find it at the bottom of the setup page of each calendar in google calendar). You can add as many as you wish.

Now, you can just call (getcals) when you want to fetch the calendars. You can put this in your .emacs to do it at startup, but it might stall your startup.

To have org-mode display the diary entries in the agenda, just add (setq org-agenda-include-diary t) in your .emacs. See the org-mode manual for details.


For integration with Google contacts there is Julien Danjou's script which you can see in action here (github repository is here):

The google-contacts for Emacs extension allows to display your Google Contacts directly inside Emacs.

Note that it is likely to only work with at least Emacs 24, since it's using oauth2 which is part of GNU ELPA.