Google Calendar API

4 views
Skip to first unread message

vanderkerkoff

unread,
Apr 10, 2008, 6:15:25 AM4/10/08
to Ruby on Rails: Talk
Hello everyone

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

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

http://benjamin.francisoud.googlepages.com/googlecalendar

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('REPLACE_WIT...@gmail.com',
'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.


vanderkerkoff

unread,
Apr 10, 2008, 7:37:14 AM4/10/08
to Ruby on Rails: Talk
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

Although it's much more likely a syntaxical errror on my behalf :-)



Conrad Taylor

unread,
Apr 10, 2008, 8:03:44 AM4/10/08
to rubyonra...@googlegroups.com
Hi, I would recommend trying to invoke the following code in the console:

require 'googlecalendar'
g = GData.new
g.login('REPLACE_WIT...@gmail.com',
'REPLACE_WITH_YOUR_PASSWORD')
calendar_list = g.get_calendars()
print calendar_list

Good luck,

-Conrad

vanderkerkoff

unread,
Apr 10, 2008, 8:44:27 AM4/10/08
to Ruby on Rails: Talk
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.

vanderkerkoff

unread,
Apr 15, 2008, 3:38:23 AM4/15/08
to Ruby on Rails: Talk
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.

vanderkerkoff

unread,
Apr 16, 2008, 5:59:49 AM4/16/08
to Ruby on Rails: Talk
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('youra...@gmail.com', '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


On Apr 15, 8:38 am, vanderkerkoff <tonm...@gmail.com> wrote:
> 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.
>
Reply all
Reply to author
Forward
0 new messages