Python 我怎样才能通过程序向Google Reader发布便条?

Python 我怎样才能通过程序向Google Reader发布便条?,python,google-reader,Python,Google Reader,我用我的谷歌阅读器笔记作为储存书签和小信息片段的地方。我想写一个小脚本,让我可以从命令行发布注释(我更喜欢Python,但是可以接受使用任何语言的答案) 这似乎是一个很好的开始&一些最新的信息。这一过程似乎是: 从{0}获取SID(会话ID)&Passwd={1} 从中获取临时令牌 使用正确的字段值发布到 所以。。。上面的第2步对我来说总是失败(得到403禁止),尝试Martin Doms C#代码也有同样的问题。谷歌似乎不再使用这种方法进行身份验证 更新。。。让我跑起来。我现在可以登录并获取令

我用我的谷歌阅读器笔记作为储存书签和小信息片段的地方。我想写一个小脚本,让我可以从命令行发布注释(我更喜欢Python,但是可以接受使用任何语言的答案)

这似乎是一个很好的开始&一些最新的信息。这一过程似乎是:

  • 从{0}获取SID(会话ID)&Passwd={1}
  • 从中获取临时令牌
  • 使用正确的字段值发布到
  • 所以。。。上面的第2步对我来说总是失败(得到403禁止),尝试Martin Doms C#代码也有同样的问题。谷歌似乎不再使用这种方法进行身份验证

    更新。。。让我跑起来。我现在可以登录并获取令牌。现在我只需要弄清楚怎么贴便条。我的代码如下:

    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 Reader便笺,您可以看到提交的内容

    它发布到的url为:

    似乎唯一需要的参数是'T'(对于在步骤2中检索的令牌)和'snippet',这是正在发布的注释

    基于此,我做了以下工作(注意导入urllib以及对帖子正文进行编码):

    您还可以设置一些其他参数,例如ck、linkify、share等,但这些参数都记录在网站上


    我将阅读命令行参数中的注释作为练习留在脚本中供读者使用。

    这会有帮助吗?它很有用,但已经过时了。谷歌在2010年6月的某个时候放弃了上述认证方法。。您已经
    urllib3
    。修复了输入错误并删除了未使用的cookielib-感谢您的帮助!这里还有一些其他参数:('title','This is title'),('url','),('srctTitle','This is src title'),('srcUrl','),('tags','user/-/label/exampletag'),('tags','user/-/label/anothertag'),('snippet','This is text of the snippet'),('share','false'),('linkify','false'),等等,
    # 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'