質問

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」である必要があります。

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top