Hi,

I'm trying to write a simple python script to add an event to a
calendar.
I cannot use the client library, so I'm struggling with the protocol.

Here is my problem:
1) ClientLogin authentication -> OK, it works
2) First POST to http://www.google.com/calendar/feeds/default/private/full
->
   OK, I use a 'X-If-No-Redirect' header and obtain a 412 error with
a
   S-cookie and a gsessionid
3) New POST to http://www.google.com/calendar/feeds/default/private/full
with
   the cookie and/or gsessionid -> I obtain a 412 error again!

Probably my error is very trivial, but I am quite inexpert with the
http protocol and don't see it.

Here is the code:

# -*- coding: utf-8 -*-
import urllib, urllib2

email = '[email protected]'
password = 'password'
clientapp = 'marco-gcsmssendpy-1'
service = 'cl'

params = urllib.urlencode({'Email': email, 'Passwd': password,
'source': clientapp, 'service': service})
req = urllib2.Request(url='https://www.google.com/accounts/
ClientLogin', data=params)
f = urllib2.urlopen(req)
for line in f.readlines():
  if line[0:5] == 'Auth=':
    authtoken=line[5:]

headers = { 'GData-Version': '2',
            'Authorization': 'GoogleLogin auth=' + authtoken,
            'Content-Type': 'application/atom+xml',
            'X-If-No-Redirect': '1' }

xmlentry = '''
<entry xmlns='http://www.w3.org/2005/Atom'
    xmlns:gd='http://schemas.google.com/g/2005'>
  <category scheme='http://schemas.google.com/g/2005#kind'
    term='http://schemas.google.com/g/2005#event'></category>
  <title type='text'>Tennis with Beth</title>
  <content type='text'>Meet for a quick lesson.</content>
  <gd:transparency
    value='http://schemas.google.com/g/2005#event.opaque'>
  </gd:transparency>
  <gd:eventStatus
    value='http://schemas.google.com/g/2005#event.confirmed'>
  </gd:eventStatus>
  <gd:where valueString='Rolling Lawn Courts'></gd:where>
  <gd:when startTime='2010-04-17T15:00:00.000Z'
    endTime='2010-04-17T17:00:00.000Z'></gd:when>
</entry>
'''

req3 = urllib2.Request(url='http://www.google.com/calendar/feeds/
default/private/full', headers=headers, data=xmlentry)

try:
  f4 = urllib2.urlopen(req3)
except urllib2.HTTPError, detail:
  # print detail.info().get('X-Redirect-Location')
  idx = detail.info().get('X-Redirect-Location').index("?gsessionid=")
  gsid = detail.info().get('X-Redirect-Location')[idx+12:]
  #idx = detail.info().get('Set-Cookie').index(";")
  #ckie = detail.info().get('Set-Cookie')[0:idx]
  req4 = urllib2.Request(url='http://www.google.com/calendar/feeds/
default/private/full', headers=headers, data=xmlentry)
  #req.add_header('Cookie', ckie)
  req4.add_header('gsessionid', gsid)
  f5 = urllib2.urlopen(req4)
  print f5.read()

raw_input("press enter to exit")


Thanks for the help.
Marco

--

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.


Reply via email to