gpt4 book ai didi

python - 我怎样才能以编程方式将笔记发布到 Google 阅读器?

转载 作者:太空宇宙 更新时间:2023-11-03 11:35:08 24 4
gpt4 key购买 nike

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

This project似乎是一个很好的起点和一些最新信息 here .该过程似乎是:

  1. https://www.google.com/accounts/ClientLogin?service=reader&Email=获取一个SID( session ID) {0}&Passwd={1}
  2. http://www.google.com/reader/api/0/token获取临时 token
  3. 发个帖子给http://www.google.com/reader/api/0/item/edit具有正确的字段值

所以...上面的第 2 步对我来说总是失败(得到 403 禁止)并且尝试 Martin Doms C# 代码有同样的问题。 Google 似乎不再使用这种方法进行身份验证。

更新... This comment让我启动并运行。我现在可以登录并获取 token 。现在我只需要弄清楚如何发布便条。我的代码如下:

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 查看提交的内容。

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

似乎唯一需要的参数是“T”(用于在步骤 2 中检索 token )和“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 阅读器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6239560/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com