python – 如何以编程方式将注释发布到Google Reader?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python – 如何以编程方式将注释发布到Google Reader?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2198字,纯文字阅读大概需要4分钟。
内容图文
我使用Google阅读器备注作为存储书签和小片段信息的地方.我想写一个小脚本让我从命令行发布笔记(我更喜欢Python,但是会接受使用任何语言的答案).
This project似乎是一个开始的好地方.一些更新的信息here.该过程似乎是:
>从https://www.google.com/accounts/ClientLogin?service=reader&Email=获取SID(会话ID){0}& Passwd = {1}
>从http://www.google.com/reader/api/0/token获取临时令牌
>使用正确的字段值对http://www.google.com/reader/api/0/item/edit进行POST
所以…上面的第2步总是对我失败(得到403被禁止)并尝试Martin Doms C#代码有同样的问题.看起来Google不再使用此方法进行身份验证.
更新… This comment让我起步并运行.我现在可以登录并获取令牌.现在我只需要弄清楚如何发布便笺.我的代码如下:
import urllib2
# Step 1: login to get session auth
email = 'myuser@gmail.com'
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...
解决方法:
如果您从浏览器添加Google阅读器备注,则可以使用Firebug查看提交的内容.
它发布的网址是:http://www.google.co.uk/reader/api/0/item/edit.
似乎唯一需要的参数是’T'(对于步骤2中的令牌检索)和’snippet’,即发布的注释.
基于此我做了以下对我有用(注意导入urllib以及编码帖子体):
# 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'
您可以设置其他一些参数,例如ck,linkify,share等,但它们都记录在网站上.
我将读取命令行参数中的注释留给脚本作为读者练习.
内容总结
以上是互联网集市为您收集整理的python – 如何以编程方式将注释发布到Google Reader?全部内容,希望文章能够帮你解决python – 如何以编程方式将注释发布到Google Reader?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。