Ruby GData API, Google Calendar, and redirects by jgn on Thursday, May 6, 2010 in Code

The Ruby GData API provides for accessing a number of Google data sources: Google Apps, Analytics, YouTube, you name it (

When you access a Google Calendar that is managed through a Google Apps username (e.g.,, as opposed to, the standard lookup feed (example: redirects after you access it. (Not the case for calendars owned by addresses, it would seem.)

Well, bizarrely, in the Ruby implementation (which you can find here: Ruby 1.9 version here:, redirects are not handled properly.

Handling a redirect is a "must have" to get into the Calendar data for a Google Apps user.

The master code repository is hosted on, so since it doesn't provide for submitting patches as easily as Github, I'll just lob a monkeypatch fix here . . .

[code language='ruby'] # Fix for GData::Client::Calendar failure to follow redirects module GData module Client class Calendar def make_request(method, url, body = '', retries = 4) response = super(method, url, body) if response.status_code == 302 and retries > 0 @session_cookie = response.headers['set-cookie'] # original wasn't capturing the redirect location redirect_url = response.headers['location'] return self.make_request(method, redirect_url, body, retries - 1) else return response end end end end end

For Rails, you can put this into a file in config/initializers

comments powered by Disqus