26

Google リーダーには 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

Google Reader は 2010 年 6 月頃に SID 認証を削除しました (私が思うに)。ClientLogin から新しい認証を使用するのが新しい方法であり、少し単純です (ヘッダーが短くなります)。をserviceリクエストするにはデータを追加する必要があります。AuthAuthservice=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 に答える