For the benefit of anyone else who might chance on this thread, this
is how I eventually did it:
require 'net/http'
require 'net/https'
require 'openssl'
def add_calendar_subscription(calendar_id)
begin
http = Net::HTTP.new('www.google.com')
path = '/calendar/feeds/default/allcalendars/full?
gsessionid=o1OUlyYzssq1oFO1aKydVg'
data = "<?xml version='1.0'?>
<entry xmlns='http://www.w3.org/2005/Atom'>
<id>#{calendar_id}</id>
</entry>"
headers = {'authorization' => "GoogleLogin
[EMAIL PROTECTED]", 'content-type' => 'application/atom+xml'}
response = http.post(path, data, headers)
return response
end
end
protected
def authorization()
http = Net::HTTP.new('www.google.com', 443)
http.verify_mode = OpenSSL::SSL::VERIFY_NONE # suppress 'peer
certificate won't be verified' warnings
http.use_ssl = true
path = '/accounts/ClientLogin'
data =
"accountType=HOSTED_OR_GOOGLE&[EMAIL PROTECTED]&[EMAIL PROTECTED]&service=cl"
headers = { 'Content-Type' =>
'application/x-www-form-urlencoded'}
resp, data = http.post(path, data, headers)
cl_string = data[/Auth=(.*)/, 1]
return cl_string
end
Hopefully that will be useful to someone else!
Mark
On Sep 30, 4:06 pm, Mark <[EMAIL PROTECTED]> wrote:
> OK, now I've figured out how to set the content-type and I'm getting a
> different error: #<Net::HTTPUnauthorized 401 Authorization required
> readbody=true>
>
> Anyone know how I can authorize the post?
>
> Thanks,
>
> Mark
>
> On Sep 29, 10:40 pm, Mark <[EMAIL PROTECTED]> wrote:
>
> > Hi Ray, I'd love to see the sample that would be really helpful.
>
> > I tried setting the content type but got the same result, maybe I
> > didn't do it right though! I put it in as another tag in the xml.
>
> > Thanks,
>
> > Mark
>
> > On Sep 29, 10:10 pm, "Ray Baxter" <[EMAIL PROTECTED]> wrote:
>
> > > I have a working sample of this code, but I can't access it right now.
> > > I'll check on it tonight.
>
> > > In the meanwhile, are you setting the content type to
> > > application/atom+xml?
>
> > > Ray
>
> > > On Mon, Sep 29, 2008 at 6:08 AM, Mark <[EMAIL PROTECTED]> wrote:
>
> > > > Hi all, I'm trying to programmatically sign up a user to a calendar in
> > > > a ruby on rails app.
>
> > > > Here's my code:
>
> > > > def add_calendar_subscription(calendar_id)
> > > > begin
> > > > srv = GoogleCalendar::Service.new(@email, @password)
> > > > calendar_id = "c4o4i7m2lbamc4k26sc2vokh5g
> > > > %40group.calendar.google.com"
>
> > > > target_url = 'www.google.com'
> > > > path = '/calendar/feeds/default/allcalendars/full'
> > > > http = Net::HTTP.new(target_url)
>
> > > > xml_request = "<?xml version='1.0'?>
> > > > <entry xmlns='http://www.w3.org/2005/Atom'>
> > > > <id>#{calendar_id}</id>
> > > > </entry>"
>
> > > > xml_response = http.post(path, xml_request)
> > > > puts xml_response.body
>
> > > > rescue GoogleCalendar::AuthenticationFailed
> > > > RAILS_DEFAULT_LOGGER.warn "[EMAIL PROTECTED] authentication
> > > > failure for
> > > > Google Cal"
> > > > end
> > > > end
>
> > > > I get an error: #<Net::HTTPUnsupportedMediaType 415 Unsupported Media
> > > > Type readbody=true>
>
> > > > when trying to set the xml_response variable.
>
> > > > Is my XML correct? I can't find any information on how it should look
> > > > other
> > > > thanhttp://code.google.com/apis/calendar/developers_guide_protocol.html#A...
> > > > which I used as a model for mine.
>
> > > > Any help would be greatly appreciated!
>
> > > > Mark
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Calendar Data API" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/google-calendar-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---