ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

python – 如何以编程方式将注释发布到Google Reader?

2019-07-04 20:55:52  阅读:183  来源: 互联网

标签:python google-reader


我使用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
来源: https://codeday.me/bug/20190704/1380808.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有