开发者

What is the best way to access Google Calendar from ruby?

开发者 https://www.devze.com 2022-12-30 21:51 出处:网络
I\'m writing an开发者_运维技巧 app for a company that uses Google Calendar internally and would need to use events they already have in their calendar in the app. So I need to get read only access to

I'm writing an开发者_运维技巧 app for a company that uses Google Calendar internally and would need to use events they already have in their calendar in the app. So I need to get read only access to their calendars from the app (namely I need the events title, start and end dates and attendee emails for all future events).

What is the simplest way to do this in ruby (I would need it to work relatively seamlessly on Heroku)?

I tried using the GCal4Ruby gem which seemed the least outdated of the ones I found but I'm unable to even authenticate through the library (HTTPRequestFailed - Captcha required error) let alone get the info I need.

Clarification: What I'm talking about is the Google Apps version of the calendar, not the one at calendar.google.com.


OK I got the api via GCal4Ruby working. I'm not exactly sure what went wrong the first time. Thanks to Mike and James for their suggestions. This is sample code I used for anyone interested:

require "rubygems"
require "gcal4ruby"

serv = GCal4Ruby::Service.new
serv.authenticate "username@example.com", "password"

events = GCal4Ruby::Event.find serv, {'start-min' => Time.now.utc.xmlschema, 
    :calendar => 'example-cal%40example.com'}

events.each do |event|
    puts event.title
    puts event.attendees.join ", "
    puts event.start_time
    puts event.end_time
    puts '-----------------------'
end


You should be able to use the Google Calendar private xml address feature to pull out the needed data.

You could then parse it with hpricot or nokogiri to extract whatever fields you need.

0

精彩评论

暂无评论...
验证码 换一张
取 消