2008-09-09 5 views
26

GoogleリーダーにはAPIがありますか?その場合、特定のユーザーのユーザー名とパスワードを知っている未読の投稿数を取得するにはどうすればよいですか?GoogleリーダーAPI未読数

+0

@GateKiller:これに「コードリクエスト」タグを投げる動機を理解しています...唯一の答えが(破損した)APIドキュメントへのリンクである質問に公開賞金をもらっています私は私のキーワードをグーグルで見つけた人に300リペアを支払うことになるだろうと私を苛立たせる。 – Shog9

+0

しかし、タグは目的を果たさない。むしろ、実際の質問にサンプルコードを理解してほしいというメモを追加する必要があります。 – Shog9

答えて

45

この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 

そして、上のいくつかの追加のリンクトピック:

+0

一般的には、juneでGoogle Reader APIに加えられた変更以来、この例はもう機能しません。 – Joe

+0

2010年8月9日の時点で、これはもう機能しません。 –

+1

この例を修正しました。 livibetterのおかげで - 私はSID - > Authの変更を読んでいましたが、「サービス」は見られませんでした。 – jimmyorr

11

thereです。しかしまだベータです。

+0

この質問は、質問されたときに質問に答えます。質問の著者がそれを十分に見つけられない何らかの理由がある場合、おそらく彼は明確にするために質問を編集するべきです。 – EBGreen

+1

そのサイトに関する多くの情報は古くなっています。 –

+1

私が好きである限り、これは公式のGoogle Reader APIではありません。これは、リバースエンジニアリングされた推測であり、いつでも破損する可能性があります。 – drozzy

0

[1]、 "トークン" フィールドは "T" であるべきである

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

+0

これは科学的な記事ではありません。あなたはリンク[1]をインラインに置くことができます! :-) – drozzy

+0

@drozzy私はあなたが冗談を言っていないという前提のもとで働いています。ヤシンは結局コロンを欠いていた。 2番目の[1]の直後のコロンはマークダウン構文に適合し、インラインリンクになります。これは、より速く、マウスクリックが必要なく、次に提供されたGUIインターフェースを使用することができます。 – Davorak

+0

申し訳ありませんが、私に何が入ったのか分かりません。 – drozzy

6

this answer

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 
に更新され

2010年6月頃にGoogle ReaderがSID authを削除しました(私は思う)、ClientLoginからの新しいAuthを使用するのは新しいやり方です。(ヘッダーは短くなります) 。 Authをリクエストするためにserviceをデータに追加する必要があります。service=readerを送信しない場合は、Authが返されませんでした。

this threadでは、認証方法の変更について詳しく読むことができます。

関連する問題