httplib2 now supports GoogleLogin for Google Data API
Posted by pat 136 days ago
Joe Gregorio added support for GoogleLogin in his Python httplib2 library.
It's in the svn tree, not yet in a release. In order to test the script you need to do:
> svn co https://svn.sourceforge.net/svnroot/httplib2/trunk httplib2
> cd httplib2
> python setup.py install
Then install elementtree and celementtree that his sample uses to parse the output (or remove that part of the sample script).
wget http://effbot.org/downloads/elementtree-1.2.6-20050316.tar.gz
tar xvfz elementtree-1.2.6-20050316.tar.gz
cd elementtree-1.2.6-20050316
python setup.py build
sudo python setup.py install
cd ..
wget http://effbot.org/downloads/cElementTree-1.0.5-20051216.tar.gz
tar xvfz cElementTree-1.0.5-20051216.tar.gz
cd cElementTree-1.0.5-20051216
python setup.py build
sudo python setup.py install
The script Joe posted, with a sample entry in it:
import httplib2
import cElementTree
def createEntry(title,content,authorName,authorEmail,where,start,end):
h = httplib2.Http()
h.follow_all_redirects = True
name, passwd = file("/Users/pat/gmail", "r").read().split()
h.add_credentials(name, passwd)
body = """%s %s %s %s """ % (title,content,authorName,authorEmail,where,start,end)
headers = {'Content-Type': 'application/atom+xml'}
uri = "http://www.google.com/calendar/feeds/default/private/full"
# Create a new entry in the calendar
resp, content = h.request(uri, "POST", body=body, headers=headers)
print body
print resp
print content
assert resp.status == 201
# Parse the response to find the Member URI
ATOM = "http://www.w3.org/2005/Atom"
ATOM_LINK = "{%s}link" % ATOM
tree = cElementTree.fromstring(content)
reledit = [l.get('href', '') for l in tree.findall(ATOM_LINK) if
l.get('rel', '') == 'edit']
# Delete the newly created event
#resp, content = h.request(reledit[0], "DELETE")
#assert resp.status == 200
createEntry('Test Gregorio\'s script','Hi Joe\, thanks for extending httplib2: it works great!','Patrick Chanezon','chanezon@gmail.com','Moutain View','2006-04-28T17:00:00-08:00','2006-04-28T18:00:00-08:00')
Very cool! Now I hope to see someone adding the same support in ruby's http-access2.