Има ли Google Reader API и ако има, как мога да получа броя на непрочетените публикации за конкретен потребител, като знам потребителското име и паролата му?
Брой непрочетени API на Google Reader
Отговори (4)
Този 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
И няколко допълнителни връзки по темата:
- http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI
- Как да имате достъп до удостоверена услуга на Google App Engine от (неуеб) клиент на Python?
- http://blog.gpowered.net/2007/08/google-reader-api-functions.html
Той е там. Все още е в бета версия.
Ето актуализация на този отговор
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
Google Reader премахна удостоверяването на SID около юни 2010 г. (мисля), че използването на ново удостоверяване от ClientLogin е новият начин и е малко по-опростен (заглавката е по-къса). Ще трябва да добавите service
в данните за искане на Auth
, забелязах, че не се връща Auth
, ако не изпратите service=reader
.
Можете да прочетете повече за промяната на метода за удостоверяване в тази тема .
В API, публикуван в [1], полето "token" трябва да бъде "T"
[1] http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI