DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Add A Friend's Calendar On Google Calendar

05.17.2009
| 3824 views |
  • submit to reddit
        This code shows how to add a friend's calendar to our Google Calendar account. 

require 'rubygems'
require 'mechanize'

agent = WWW::Mechanize.new
page = agent.get('https://www.google.com/accounts/ServiceLogin')
form = page.forms.first
form.Email = "user@gmail.com"
form.Passwd = "mypassword"
page2 = agent.submit(form)
page3 = agent.get("http://www.google.com/calendar")
secid = page3.header['set-cookie'].match(/secid=(.*),/)[1]

data = {
  "cid" => "23489dfskj12342gh34kj32434@group.calendar.google.com",  
  "hl" => "en",
  "lact" => "ADD",
  "ltyp" => "0",
  "secid" => secid,
}  
agent.post("http://www.google.com/calendar/editcallist", data)