代码之家  ›  专栏  ›  技术社区  ›  GateKiller

谷歌阅读器API未读计数

  •  26
  • GateKiller  · 技术社区  · 16 年前

    谷歌阅读器是否有一个API,如果有,我如何才能为知道用户名和密码的特定用户计算未读帖子的数量?

    4 回复  |  直到 12 年前
        1
  •  45
  •   Community Mike Causer    7 年前

    此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
    

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

        2
  •  11
  •   Gulzar Nazim    16 年前

    它是 there . 不过还在测试阶段。

        3
  •  6
  •   Community Mike Causer    7 年前

    这是对 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
    

    GoogleReader在2010年6月左右删除了sid-auth(我认为),从clientlogin中使用new-auth是一种新的方法,而且它更简单(头更短)。您必须添加 service 在用于请求的数据中 Auth 我没有注意到 奥思 如果不发送 service=reader .

    您可以在中了解更多有关身份验证方法更改的信息。 this thread .

        4
  •  0
  •   yassin    14 年前

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

    〔1〕 http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI