如何以编程方式向 Google 阅读器发布注释?
我使用 Google Reader 笔记作为存储书签和小信息片段的地方。我想编写一个小脚本,让我从命令行发布注释(我更喜欢Python,但使用任何语言的答案都将被接受)。
此项目似乎是一个不错的起点更多最新信息在这里。该过程似乎是:
- 从 https:// 获取 SID(会话 ID) www.google.com/accounts/ClientLogin?service=reader&Email={0}&Passwd={1}
- 从 http://www.google.com/reader/api/0/token
- 制作发布到 http://www.google.com/reader/api/0/item /edit 使用正确的字段值
所以...上面的步骤 2对我来说总是失败(得到 403 禁止)并且尝试 Martin Doms C# 代码也有同样的问题。看来 Google 不再使用此方法进行身份验证。
更新... 这条评论让我开始运行。我现在可以登录并获取令牌。现在我只需要弄清楚如何发布注释。我的代码如下:
import urllib2
# Step 1: login to get session auth
email = '[email protected]'
passwd = 'mypassword'
response = urllib2.urlopen('https://www.google.com/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('http://www.google.com/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...
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:
- Get a SID (session ID) from https://www.google.com/accounts/ClientLogin?service=reader&Email={0}&Passwd={1}
- Get a temporary token from http://www.google.com/reader/api/0/token
- Make a POST to http://www.google.com/reader/api/0/item/edit with the correct field values
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 = '[email protected]'
passwd = 'mypassword'
response = urllib2.urlopen('https://www.google.com/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('http://www.google.com/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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您从浏览器添加 Google Reader 注释,则可以使用 Firebug 查看提交的内容。
它发布到的网址是:http://www.google.co。 uk/reader/api/0/item/edit。
似乎唯一需要的参数是“T”(用于步骤 2 中的令牌检索)和“snippet”,即正在发布的注释。
基于此,我做了以下对我有用的操作(注意 import urllib 以及对帖子正文进行编码):
还有一些其他参数可以设置,例如 ck、linkify、share 等,但它们都记录在网站上。
我将阅读脚本命令行参数的注释作为读者的练习。
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):
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.