Over a million developers have joined DZone.

Add A Friend's Calendar On Google Calendar

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)

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}