题
Google Reader 是否有 API?如果有,我如何获取知道其用户名和密码的特定用户的未读帖子数?
解决方案
此 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
以及有关该主题的一些附加链接:
其他提示
这是 那里. 。但仍处于测试阶段。
这是一个更新 这个答案
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 Reader 在 2010 年 6 月左右删除了 SID 身份验证(我认为),使用来自 ClientLogin 的新身份验证是新方法,而且它更简单一些(标头更短)。你必须添加 service
在请求数据中 Auth
, ,我注意到没有 Auth
如果您不发送则返回 service=reader
.
您可以阅读有关身份验证方法更改的更多信息 这个线程.
在[1]中发布的API中,“token”字段应为“T”
不隶属于 StackOverflow