2008-09-09 3 views
26

Google 리더에 API가 있습니까? 그렇다면 특정 사용자의 사용자 이름과 비밀번호를 알 수있는 읽지 않은 게시물 수를 계산하려면 어떻게해야합니까?Google 리더 API 읽지 않음 횟수

+0

@GateKiller : "코드 요청"태그를이 코드에 던지려는 동기를 이해합니다 ... 유일한 답변은 (깨진) API 문서에 대한 링크 인 질문에 열린 현상금이 있습니다. 내 키워드를 인터넷으로 검색 한 사람에게 300 원을 지불해야한다는 것을 나에게 짜증나게한다. – Shog9

+0

그러나 태그는 어떤 용도로도 사용되지 않습니다. 오히려 샘플 코드를 감상 할 수 있다는 메모를 실제 질문에 추가해야합니다. – Shog9

답변

45

이 URL은 피드 당 읽지 않은 글 수를 제공합니다. 그런 다음 피드를 반복하여 카운트를 합산 할 수 있습니다.

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 

그리고 몇 가지 추가 링크 : 여기

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

는 XML/JSON을 구문 분석하고 수를 합산하여 독자들에게 연습 문제로 남겨 ... 파이썬에서 미니멀 한 예이다 주제 :

+0

일반적인 경우 - june에서 Google 리더 API를 변경 한 이후로이 예제는 더 이상 작동하지 않습니다 ... – Joe

+0

2010 년 8 월 9 일 당시, 더 이상 작동하지 않습니다. –

+1

이 예제를 수정했습니다. livibetter에게 감사드립니다 - SID -> Auth 변경에 대해 읽었지만 어디서나 '문서'부분이 문서화 된 '서비스'는 보지 못했습니다. – jimmyorr

11

there입니다. 그래도 베타 버전입니다.

+0

이 질문은 묻는대로 질문에 대답합니다. 질문 작성자가 충분하지 않은 이유가 있다면 아마도 질문을 수정하여 명확하게해야합니다. – EBGreen

+1

해당 사이트의 많은 정보가 구식입니다. –

+1

내가 원했던만큼, 이것은 공식 Google 리더 API가 아닙니다. 어느 순간에 깨질 수있는 리버스 엔지니어링 된 추측 일뿐입니다. – drozzy

0

[1]은 "토큰"필드

[1] 여기

+0

이것은 과학적 기사가 아닙니다. 링크 [1]을 인라인으로 배치 할 수 있습니다! :-) – drozzy

+0

@drozzy 나는 농담하지 않는다는 가정하에 일하고있다.야신은 모두 결장을 놓쳤다. 두 번째 [1] 바로 뒤에있는 콜론은 markdown 구문에 적합하고 인라인 링크로 만듭니다. 마우스를 클릭 할 필요가 없으며 제공된 gui 인터페이스를 사용하면 더 빨리 수행 할 수 있습니다. – Davorak

+0

미안, 무슨 일이 있었는지 모르겠다. – drozzy

6

http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI가 업데이트 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 
에 "T"이어야

Google 리더는 2010 년 6 월경 SID auth가 제거되었습니다. ClientLogin의 새로운 인증을 사용하는 것이 새로운 방법이며 조금 더 간단합니다 (헤더가 짧음) . Auth을 요청하기 위해 service을 데이터에 추가해야합니다. service=reader을 보내지 않으면 Auth이 반환됩니다.

this thread에서 인증 방법 변경에 대한 자세한 내용을 볼 수 있습니다.

관련 문제