首页 / 知识

Google Reader API未读计数

2023-04-14 18:10:00

Google Reader API未读计数

Google Reader API Unread Count

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


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

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

这是Python中的一个极简示例...解析xml / json并累加计数作为练习供读者阅读:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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('\
') 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

在那里。虽然仍处于Beta版。


这是此答案的更新

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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('\
') 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中的新Auth是新方法,并且更简单(标题更短)。您必须在数据中添加service来请求Auth,如果您不发送service=reader,我注意到没有返回Auth

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


在[1]中发布??的API中,"令牌"字段应为" T"

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


用户密码用户名阅读器

最新内容

相关内容

猜你喜欢