26

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

4

4 回答 4

45

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

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

以及有关该主题的一些其他链接:

于 2009-02-24T15:06:23.323 回答
11

它在那里。虽然仍处于测试阶段。

于 2008-09-09T20:55:41.247 回答
6

这是此答案的更新

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

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

您可以在此线程中阅读有关身份验证方法更改的更多信息。

于 2010-08-18T23:40:35.620 回答
0

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

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

于 2010-04-07T17:51:10.180 回答