我将Google阅读器笔记用作存储书签和少量信息片段的地方.我想写一个小脚本,让我从命令行发布便笺(我更喜欢Python,但是可以接受使用任何语言的答案).
I use my Google Reader notes as a place to store bookmarks and small snippets of information. I would like to write a small script to let me post notes from the command line (I prefer Python,but an answer using any language will be accepted).
此项目似乎是开始&一些最新信息这里.该过程似乎是:
This project seemed to be a be a good place to start & some more up-to-date information here. The process appears to be:
所以...上面的第2步对我而言始终失败(禁止使用403),尝试Martin Doms C#代码也存在相同的问题.看来Google不再使用此方法进行身份验证.
So... step 2 above always fails for me (get a 403 forbidden) and trying Martin Doms C# code has the same issue. It looks like Google no longer use this method for authentication.
更新... 此评论使我开始工作.我现在可以登录并获得令牌.现在,我只需要弄清楚如何发布便笺.我的代码如下:
Update... This comment got me up and running. I can now log in and get a token. Now I just need to figure out how to POST the note. My code is below:
import urllib2 # Step 1: login to get session auth email = 'myuser@gmail' passwd = 'mypassword' response = urllib2.urlopen('www.google/accounts/ClientLogin?service=reader&Email=%s&Passwd=%s' % (email,passwd)) data = response.read() credentials = {} for line in data.split('\n'): fields = line.split('=') if len(fields)==2: credentials[fields[0]]=fields[1] assert credentials.has_key('Auth'),'no Auth in response' # step 2: get a token req = urllib2.Request('www.google/reader/api/0/token') req.add_header('Authorization', 'GoogleLogin auth=%s' % credentials['Auth']) response = urllib2.urlopen(req) # step 3: now POST the details of note # TBD...推荐答案
使用Firebug,如果您从浏览器添加Google阅读器注释,则可以看到提交了什么内容.
Using Firebug you can see what gets submitted if you add a Google Reader note from a browser.
发布到的网址是: www.google .co.uk/reader/api/0/item/edit .
似乎唯一需要的参数是"T"(用于在步骤2检索令牌)和"snippet"(即要发布的注释).
It seems that the only required parameters are 'T' (for the token retrieve at step 2) and 'snippet' which is the note being posted.
基于此,我做了对我有用的以下操作(请注意,导入urllib还要对帖子正文进行编码):
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 = "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'您可以设置其他一些参数,例如ck,linkify,分享等,但它们都记录在网站上.
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.
更多推荐
如何以编程方式向Google阅读器发布笔记?
发布评论