문제

Google 리더에 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 리더는 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