Pergunta

O Google Reader tem uma API e, em caso afirmativo, como posso obter a contagem do número de mensagens não lidas para um usuário específico, sabendo o seu nome de utilizador e a palavra-passe?

Foi útil?

Solução

Esta URL irá dar-lhe uma contagem de novos posts por feed.Em seguida, você pode iterar sobre os feeds e soma-se a conta.

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

Aqui é um minimalista exemplo em Python...analisar o xml/json e somando a conta é deixado como um exercício para o leitor:

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 alguns links sobre o tema:

Outras dicas

É .Ainda em versão Beta, porém.

Aqui está uma atualização para esta resposta

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

O Google Reader removido SID auth por volta de junho, 2010 (eu acho), usando o novo Auth do ClientLogin é a nova forma e é um pouco mais simples (cabeçalho é mais curto).Você terá que adicionar service dados para pedido Auth, Eu notei nenhum Auth devolvido se você não enviar o service=reader.

Você pode ler mais sobre a mudança do método de autenticação em esta thread.

Na API publicada em [1], o "token" campo deve ser "T"

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top