Domanda

Google Reader dispone di un'API e, in tal caso, come posso ottenere il conteggio del numero di post non letti per un utente specifico conoscendone nome utente e password?

È stato utile?

Soluzione

Questo URL ti fornirà il conteggio dei post non letti per feed.È quindi possibile scorrere i feed e sommare i conteggi.

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

Ecco un esempio minimalista in Python... l'analisi di xml/json e la somma dei conteggi viene lasciata come esercizio per il lettore:

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

E alcuni link aggiuntivi sull'argomento:

Altri suggerimenti

È .Ancora in Beta però.

Ecco un aggiornamento a questa risposta

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 ha rimosso l'autenticazione SID intorno a giugno 2010 (credo), l'utilizzo della nuova autenticazione da ClientLogin è il nuovo modo ed è un po' più semplice (l'intestazione è più breve).Dovrai aggiungere service nei dati per la richiesta Auth, ho notato di no Auth restituito se non invii il file service=reader.

Puoi leggere ulteriori informazioni sulla modifica del metodo di autenticazione in questo filo.

Nell'API pubblicata in [1], il campo "token" dovrebbe essere "T"

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top