Recuento de no leídos de la API de Google Reader
-
09-06-2019 - |
Pregunta
¿Google Reader tiene una API? Si es así, ¿cómo puedo obtener el recuento de publicaciones no leídas de un usuario específico conociendo su nombre de usuario y contraseña?
Solución
Esta URL le dará un recuento de publicaciones no leídas por feed.Luego puede iterar sobre los feeds y resumir los recuentos.
http://www.google.com/reader/api/0/unread-count?all=true
Aquí hay un ejemplo minimalista en Python... analizar xml/json y sumar los recuentos se deja como ejercicio para el lector:
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
Y algunos enlaces adicionales sobre el tema:
Otros consejos
Es allá.Aunque todavía está en Beta.
Aquí hay una actualización de esta respuesta
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 eliminó la autenticación SID alrededor de junio de 2010 (creo), usar la nueva autenticación de ClientLogin es la nueva forma y es un poco más simple (el encabezado es más corto).tendrás que agregar service
en datos para solicitar Auth
, noté que no Auth
devuelto si no envías el service=reader
.
Puede leer más sobre el cambio de método de autenticación en este hilo.
En la API publicada en [1], el campo "token" debe ser "T"