How can I can I programatically post a note to Google Reader?

China☆狼群 提交于 2019-12-05 18:00:46

Using Firebug you can see what gets submitted if you add a Google Reader note from a browser.

The url it posts to is : http://www.google.co.uk/reader/api/0/item/edit.

It seems that the only required parameters are 'T' (for the token retrieve at step 2) and 'snippet' which is the note being posted.

Based on that I did the following which works for me (note import urllib as well encode the post body):

# step 3: now POST the details of note

import urllib

token = response.read()
add_note_url = "http://www.google.co.uk/reader/api/0/item/edit"
data = {'snippet' : 'This is the note', 'T' : token}
encoded_data = urllib.urlencode(data)
req = urllib2.Request(add_note_url, encoded_data)
req.add_header('Authorization', 'GoogleLogin auth=%s' % credentials['Auth'])
response = urllib2.urlopen(req)

# this part is optional
if response.code == 200:
    print 'Gadzooks!'
else:
    print 'Curses and damnation'

There are a couple of other params that you can set e.g. ck, linkify, share etc, but they are all documented on the site.

I leave reading the note from a command line argument to the script as an exercise for the reader.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!