# Google Calendar API

**URL:** <https://www.ruby-forum.com/t/google-calendar-api/134383>\
**Category:** Rails\
**Created:** [April 10, 2008, 12:16pm UTC](https://www.ruby-forum.com/t/google-calendar-api/134383 "2008-04-10T12:16:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanderkerkoff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7feea3/32.png) [@vanderkerkoff](https://www.ruby-forum.com/u/vanderkerkoff)\
**Post date:** [April 10, 2008, 12:16pm UTC](https://www.ruby-forum.com/t/google-calendar-api/134383/1 "2008-04-10T12:16:04Z")

</div>

Hello everyone

Does anyone have any experience of accessing the Google C. API  
with Rails?

I’m using Ben’s page as a starting point.

> **[Google Sites: Sign-in](https://accounts.google.com/v3/signin/identifier?continue=https%3A%2F%2Fsites.google.com%2Fsite%2Fsites%2Fsystem%2Ferrors%2FWebspaceNotFound%3Fpath%3D%2Fbenjaminfrancisoud%2Fgooglecalendar&followup=https%3A%2F%2Fsites.google.com%2Fsite%2Fsites%2Fsystem%2Ferrors%2FWebspaceNotFound%3Fpath%3D%2Fbenjaminfrancisoud%2Fgooglecalendar&ifkv=AeDOFXgiUUkpiC6jXV4t9N23Od-Mz0d6VDSuiVgwtb79N36iX1r3zzfkFql8dEI40IcniBVEpLZNPw&passive=1209600&service=jotspot&flowName=GlifWebSignIn&flowEntry=ServiceLogin&dsh=S-536246598%3A1690797868481508)**
>
> Access Google Sites with a personal Google account or Google Workspace account (for business use).

I’ve installed the libraries but I can get data, I can add data, good  
start.

I’m now starting to use the get\_calendars method of the gdata class  
and I’m having problems.

Namely, this bit of code

require ‘googlecalendar’  
g = GData.new  
g.login(‘removed\_email\_address@domain.invalid’,  
‘REPLACE\_WITH\_YOUR\_PASSWORD’)  
calendar\_list = g.get\_calendars()  
print calendar\_list

Now I’m getting back a 200 OK message object back, I thought I’d be  
getting an array of calendars I’m a member of.

Has anyone been down this track?

Any information would be helpful and I’ll gladly share my experience  
of setting this up with anyone else.

---

<div class="post-metadata">

**Author:** ![vanderkerkoff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7feea3/32.png) [@vanderkerkoff](https://www.ruby-forum.com/u/vanderkerkoff)\
**Post date:** [April 10, 2008, 1:38pm UTC](https://www.ruby-forum.com/t/google-calendar-api/134383/2 "2008-04-10T13:38:08Z")

</div>

A bit more information, if I output this instead I can see exactly  
what I’m getting back.

print calendar\_list.inspect

This gives me back

#\<Net::HTTPOK 200 OK readbody=true\>

calendar\_list.each { |key, value| print key + ’ = ’ + value + “\n” }

gives me back

\<Net::HTTPOK 200 OK readbody=true\>last-modified = Thu, 10 Apr 2008  
11:32:57 GMT  
cache-control = max-age=0, must-revalidate, private  
connection = Close  
date = Thu, 10 Apr 2008 11:32:57 GMT  
content-type = application/atom+xml; charset=UTF-8  
server = GFE/1.3  
transfer-encoding = chunked

I’m starting to think that the get\_calendars method is not doing what  
it describes itself doing in it’s own logic here

[http://pastie.caboo.se/178486](http://pastie.caboo.se/178486)

Although it’s much more likely a syntaxical errror on my behalf 🙂

---

<div class="post-metadata">

**Author:** ![vanderkerkoff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7feea3/32.png) [@vanderkerkoff](https://www.ruby-forum.com/u/vanderkerkoff)\
**Post date:** [April 10, 2008, 2:04pm UTC](https://www.ruby-forum.com/t/google-calendar-api/134383/3 "2008-04-10T14:04:35Z")

</div>

Hi, I would recommend trying to invoke the following code in the  
console:  
require ‘googlecalendar’  
g = GData.new  
g.login(‘removed\_email\_address@domain.invalid’,  
‘REPLACE\_WITH\_YOUR\_PASSWORD’)  
calendar\_list = g.get\_calendars()  
print calendar\_list

Good luck,

-Conrad

---

<div class="post-metadata">

**Author:** ![vanderkerkoff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7feea3/32.png) [@vanderkerkoff](https://www.ruby-forum.com/u/vanderkerkoff)\
**Post date:** [April 10, 2008, 2:45pm UTC](https://www.ruby-forum.com/t/google-calendar-api/134383/4 "2008-04-10T14:45:12Z")

</div>

Hi Conrad, thanks for getting back to me.

The code you suggested I try is exactly the same code that I pasted  
into the ticket initially 🙂

I found the problem.

In the get\_calendars() method the redirect\_response was being  
returned, not the redirect\_data.

Changing that line to return redirect\_data gives me exactly what I was  
looking for, a list of calendars that I have access to.

Thanks anyway Conrad.

---

<div class="post-metadata">

**Author:** ![vanderkerkoff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7feea3/32.png) [@vanderkerkoff](https://www.ruby-forum.com/u/vanderkerkoff)\
**Post date:** [April 15, 2008, 9:39am UTC](https://www.ruby-forum.com/t/google-calendar-api/134383/5 "2008-04-15T09:39:08Z")

</div>

Ahh

Don’t listen to me

There’s nothing wrong with the redirect\_response line, I wasn’t using  
the right syntax to get at the data.

print calendar\_list.body

That’s the puppy.

---

<div class="post-metadata">

**Author:** ![vanderkerkoff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7feea3/32.png) [@vanderkerkoff](https://www.ruby-forum.com/u/vanderkerkoff)\
**Post date:** [April 16, 2008, 12:00pm UTC](https://www.ruby-forum.com/t/google-calendar-api/134383/6 "2008-04-16T12:00:42Z")

</div>

Worked it out in the end.

Here’s how you access your GData get\_calendars() data and strip out  
the ID of each entry(calendar) and the name of each entry and create a  
hash out of the data to use somewhere else.

require ‘hpricot’  
require ‘googlecalendar’

k = GData.new  
k.login(‘removed\_email\_address@domain.invalid’, ‘yourpassword’)  
bcalendar\_list = k.get\_calendars()  
calendar\_list = bcalendar\_list.body  
doc = Hpricot(bcalendar\_list.body.to\_s)  
@cal\_names = Hash.new  
(doc/:entry).each do |item|  
@cal\_names[item/:id] = item/:name  
end
