如何以编程方式向Google阅读器发布笔记? [英] How can I can I programatically post a note to Google Reader?

查看:75
本文介绍了如何以编程方式向Google阅读器发布笔记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将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:

  1. https://www.google.com/获取一个SID(会话ID) .com/accounts/ClientLogin?service = reader& Email = {0}& Passwd = {1}
  2. http://www.google.com/reader/api获取临时令牌/0/令牌
  3. http://www.google.com/reader/进行发布api/0/item/edit 具有正确的字段值
  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

所以...上面的第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.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...

推荐答案

使用Firebug,如果您从浏览器添加Google阅读器注释,则可以看到提交了什么内容.

Using Firebug you can see what gets submitted if you add a Google Reader note from a browser.

发布到的网址是: http://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 = "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,分享等,但它们都记录在网站上.

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阅读器发布笔记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆