Question

Est-ce que Google Reader ont une API et si oui, comment puis-je obtenir le nombre de le nombre de messages non lus pour un utilisateur spécifique, en sachant que leurs nom d'utilisateur et le mot de passe?

Était-ce utile?

La solution

Cette URL vous donnera un nombre de messages non lus par flux.Vous pouvez ensuite effectuer une itération sur les flux et la somme des comtes.

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

Ici est un minimaliste exemple en Python...l'analyse du xml/json et en additionnant le nombre de comptes est laissé comme exercice pour le lecteur:

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

Et quelques liens supplémentaires sur le sujet:

Autres conseils

Il est il y.Encore en version Bêta si.

Voici une mise à jour cette réponse

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 retiré SID auth autour de juin 2010 (je crois), en utilisant de nouveaux Auth de ClientLogin est la nouvelle façon et c'est un peu plus simple (en-tête est plus courte).Vous aurez à ajouter service dans les données du requérant Auth, J'ai remarqué que personne n' Auth retourné si vous n'envoyez pas la service=reader.

Vous pouvez en savoir plus sur le changement de méthode d'authentification ce fil.

Dans l'API, affichés dans [1], le "jeton" champ doit être en "T"

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top