【问题标题】:Google Reader API Unread Count谷歌阅读器 API 未读计数
【发布时间】:2010-09-08 08:21:36
【问题描述】:

Google Reader 是否有 API,如果有,我如何获取知道用户名和密码的特定用户的未读帖子数?

【问题讨论】:

  • @GateKiller:我理解将“代码请求”标签扔到这里的动机......我也有一个问题的开放赏金,其中唯一的答案是一个链接到(破碎) API 文档,这让我很恼火,因为我最终会向刚刚在 Google 上搜索我的关键字的人支付 300 个代表。
  • 但是,标签没有任何作用。相反,您应该在您的实际问题中添加一条注释,说明您希望使用示例代码。

标签: api google-reader


【解决方案1】:

此网址将为您提供每个供稿的未读帖子计数。然后,您可以遍历提要并总结计数。

http://www.google.com/reader/api/0/unread-count?all=true

这是 Python 中的一个极简示例...解析 xml/json 并对计数求和留给读者作为练习:

import urllib
import urllib2

username = 'username@gmail.com'
password = '******'

# Authenticate to obtain SID
auth_url = 'https://www.google.com/accounts/ClientLogin'
auth_req_data = urllib.urlencode({'Email': username,
                                  'Passwd': password,
                                  'service': 'reader'})
auth_req = urllib2.Request(auth_url, data=auth_req_data)
auth_resp = urllib2.urlopen(auth_req)
auth_resp_content = auth_resp.read()
auth_resp_dict = dict(x.split('=') for x in auth_resp_content.split('\n') if x)
auth_token = auth_resp_dict["Auth"]

# Create a cookie in the header using the SID 
header = {}
header['Authorization'] = 'GoogleLogin auth=%s' % auth_token

reader_base_url = 'http://www.google.com/reader/api/0/unread-count?%s'
reader_req_data = urllib.urlencode({'all': 'true',
                                    'output': 'xml'})
reader_url = reader_base_url % (reader_req_data)
reader_req = urllib2.Request(reader_url, None, header)
reader_resp = urllib2.urlopen(reader_req)
reader_resp_content = reader_resp.read()

print reader_resp_content

还有一些关于该主题的附加链接:

【讨论】:

  • 出于一般兴趣 - 由于 6 月份对 Google Reader API 进行了更改,此示例不再有效...
  • 修复了这个例子。感谢 livibetter - 我已经阅读了 SID -> Auth 更改,但没有看到 'service': 'reader' 部分记录在任何地方。
  • 太棒了!人们在 Google Api 的跟踪器上启动这张票也很重要,以便 Google 停止将人们锁定在 greader 中:code.google.com/p/gdata-issues/issues/…
【解决方案2】:

它是there。不过仍处于测试阶段。

【讨论】:

  • 这个问题回答了被问到的问题。如果出于某种原因,问题作者认为它不够充分,也许他应该编辑他的问题以澄清。
  • 尽管我愿意,但这不是官方的 Google Reader api。这只是逆向工程的猜测,随时可能崩溃。
【解决方案3】:

这是this answer的更新

import urllib
import urllib2

username = 'username@gmail.com'
password = '******'

# Authenticate to obtain Auth
auth_url = 'https://www.google.com/accounts/ClientLogin'
#auth_req_data = urllib.urlencode({'Email': username,
#                                  'Passwd': password})
auth_req_data = urllib.urlencode({'Email': username,
                                  'Passwd': password,
                                  'service': 'reader'})
auth_req = urllib2.Request(auth_url, data=auth_req_data)
auth_resp = urllib2.urlopen(auth_req)
auth_resp_content = auth_resp.read()
auth_resp_dict = dict(x.split('=') for x in auth_resp_content.split('\n') if x)
# SID = auth_resp_dict["SID"]
AUTH = auth_resp_dict["Auth"]

# Create a cookie in the header using the Auth
header = {}
#header['Cookie'] = 'Name=SID;SID=%s;Domain=.google.com;Path=/;Expires=160000000000' % SID
header['Authorization'] = 'GoogleLogin auth=%s' % AUTH

reader_base_url = 'http://www.google.com/reader/api/0/unread-count?%s'
reader_req_data = urllib.urlencode({'all': 'true',
                                    'output': 'xml'})
reader_url = reader_base_url % (reader_req_data)
reader_req = urllib2.Request(reader_url, None, header)
reader_resp = urllib2.urlopen(reader_req)
reader_resp_content = reader_resp.read()

print reader_resp_content

Google 阅读器在 2010 年 6 月左右删除了 SID 身份验证(我认为),使用来自 ClientLogin 的新身份验证是一种新方式,并且更简单(标题更短)。您必须在数据中添加service 以请求Auth,我注意到如果您不发送service=reader,则不会返回Auth

您可以在this thread阅读更多关于身份验证方法的变化。

【讨论】:

    【解决方案4】:

    在[1]中发布​​的API中,“token”字段应该是“T”

    [1]http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI

    【讨论】:

    • 这不是一篇科学文章。您可以将链接 [1] 内联! :-)
    • @drozzy 我假设你不是在开玩笑。亚辛所做的只是错过了一个冒号。第二个 [1] 之后的冒号符合 markdown 语法并使其成为内联链接。这可以更快,无需鼠标点击,然后使用提供的 gui 界面。
    • 抱歉,不知道是怎么回事。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-28
    • 2011-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多