Does Google Reader have an API and if so, how can I get the count of the number of unread posts for a specific user knowing their username and password?
This question answers the question as it is asked. If there is some reason why the question author does not find it sufficient, perhaps he should edit his question to clarify.
EBGreen
2009-02-24 15:40:23
A lot of the information on that site is outdated.
Martin Doms
2009-10-16 21:20:40
As much as I would like it, this is NOT an official Google Reader api. It is merely reverse-engineered guess that can break at any moment.
drozzy
2010-07-08 19:58:42
+23
A:
This URL will give you a count of unread posts per feed. You can then iterate over the feeds and sum up the counts.
http://www.google.com/reader/api/0/unread-count?all=true
Here is a minimalist example in Python...parsing the xml/json and summing the counts is left as an exercise for the reader:
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
And some additional links on the topic:
jimmyorr
2009-02-24 15:06:23
For general interst - since the changes made to Google Reader API in june, this example no longer works...
Joe Reddington
2010-07-08 17:23:42
Fixed this example. Thanks to livibetter -- I had read up on the SID -> Auth change, but didn't see the 'service': 'reader' part documented anywhere.
jimmyorr
2010-08-19 14:02:37
Daniel Ribeiro
2010-08-19 17:39:49
+3
A:
Here is an update to this answer
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 removed SID auth around June, 2010 (I think), using new Auth from ClientLogin is the new way and it's a bit simpler (header is shorter). You will have to add service
in data for requesting Auth
, I noticed no Auth
returned if you don't send the service=reader
.
You can read more about the change of authentication method in this thread.
livibetter
2010-08-18 23:40:35