如何以编程方式向Google阅读器发布笔记?

编程入门 行业动态 更新时间:2024-10-08 18:39:42
本文介绍了如何以编程方式向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:

  • 从 www.google/获取一个SID(会话ID) /accounts/ClientLogin?service = reader& Email = {0}& Passwd = {1}
  • 从 www.google/reader/api获取临时令牌/0/令牌
  • 对 www.google/reader/进行发布api/0/item/edit 具有正确的字段值
  • Get a SID (session ID) from www.google/accounts/ClientLogin?service=reader&Email={0}&Passwd={1}
  • Get a temporary token from www.google/reader/api/0/token
  • Make a POST to www.google/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' passwd = 'mypassword' response = urllib2.urlopen('www.google/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('www.google/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.

    发布到的网址是: 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 = "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阅读器发布笔记?

    本文发布于:2023-11-09 07:55:52,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1571797.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:阅读器   方式   笔记   Google

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!