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?
-
@GateKiller: I understand the motivation for throwing a "code-request" tag onto this... I also have an open bounty on a question where the only answer is a link to the (broken) API documentation, and it irritates me that i'll end up paying out 300 rep to someone who just Googled my keywords. – Shog9 Feb 24 '09 at 17:28
-
But, the tag doesn't serve any purpose. Rather, you should add a note to your actual question stating you'd appreciate sample code. – Shog9 Feb 24 '09 at 17:29
4 Answers
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 = '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
And some additional links on the topic:
-
For general interst - since the changes made to Google Reader API in june, this example no longer works... – Joe Jul 08 '10 at 17:23
-
1Fixed 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 Aug 19 '10 at 14:02
-
4Great! It is also important for people to start this ticket on Google Api's tracker, so that Google stop locking people into greader: http://code.google.com/p/gdata-issues/issues/detail?id=29&sort=-stars&colspec=API%20ID%20Type%20Status%20Priority%20Stars%20Summary – Daniel Ribeiro Aug 19 '10 at 17:39
It is there. Still in Beta though.

- 51,744
- 26
- 128
- 170
-
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 Feb 24 '09 at 15:40
-
1As 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. – Andriy Drozdyuk Jul 08 '10 at 19:58
Here is an update to this answer
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 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.

- 1
- 1

- 19,832
- 3
- 42
- 42
In the API posted in [1], the "token" field should be "T"

- 6,529
- 7
- 34
- 39
-
This is not a scientific article. You can place links [1] inline! :-) – Andriy Drozdyuk Jul 08 '10 at 19:59
-
@drozzy I am working under the assumption you are not joking. All Yassin did was miss a colon. A colon directly after the second [1] fits the markdown syntax and makes it an inline link. This can be quicker, no mouse clicks needed, then using the provided gui interface. – Davorak Jan 29 '11 at 00:53
-