如何以编程方式向 Google 阅读器发布注释?

发布于 2024-11-13 06:31:19 字数 1937 浏览 2 评论 0原文

我使用 Google Reader 笔记作为存储书签和小信息片段的地方。我想编写一个小脚本,让我从命令行发布注释(我更喜欢Python,但使用任何语言的答案都将被接受)。

此项目似乎是一个不错的起点更多最新信息在这里。该过程似乎是:

  1. https:// 获取 SID(会话 ID) www.google.com/accounts/ClientLogin?service=reader&Email={0}&Passwd={1}
  2. http://www.google.com/reader/api/0/token
  3. 制作发布到 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:

  1. Get a SID (session ID) from https://www.google.com/accounts/ClientLogin?service=reader&Email={0}&Passwd={1}
  2. Get a temporary token from http://www.google.com/reader/api/0/token
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缺⑴份安定 2024-11-20 06:31:19

如果您从浏览器添加 Google Reader 注释,则可以使用 Firebug 查看提交的内容。

它发布到的网址是:http://www.google.co。 uk/reader/api/0/item/edit

似乎唯一需要的参数是“T”(用于步骤 2 中的令牌检索)和“snippet”,即正在发布的注释。

基于此,我做了以下对我有用的操作(注意 import 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 等,但它们都记录在网站上。

我将阅读脚本命令行参数的注释作为读者的练习。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文