Google Reader API未读计数
时间:2020-03-05 18:50:21 来源:igfitidea点击:
Google阅读器是否有API,如果有,我如何知道特定用户名和密码的特定用户的未读帖子数?
解决方案
回答
在那里。虽然仍处于Beta版。
回答
该URL将为我们提供每个提要中未读帖子的数量。然后,我们可以遍历提要并汇总计数。
http://www.google.com/reader/api/0/unread-count?all=true
这是Python中的一个极简示例...解析xml / json并对计数进行求和,以供读者练习:
import urllib import urllib2 username = '[email protected]' 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
以及有关该主题的一些其他链接:
- http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI
- 如何从(非网络)python客户端访问经过身份验证的Google App Engine服务?
- http://blog.gpowered.net/2007/08/google-reader-api-functions.html
回答
在[1]中发布的API中,"令牌"字段应为" T"
[1] http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI
回答
这是此答案的更新
import urllib import urllib2 username = '[email protected]' 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中的新Auth是新方法,它更简单(标头更短)。我们必须在数据中添加service
才能请求Auth
,如果我们不发送service = reader
,我注意到没有Auth
返回。
我们可以在此线程中阅读有关身份验证方法更改的更多信息。