My favorites | Sign in
Project Logo
                
Search
for
Updated Jul 13, 2007 by gissehel
Labels: Document-API
GoogleReaderAPI  

Note : This document is totally unofficial. You should not rely on anything on this document is you need an exact information. Google Reader API has not officially been released. This document has been made mainly by reverse engeneering the protocol.

Requierements

Google Reader API require :

  • http client
  • GET and POST support
  • Cookie support
  • https client

https is only required for identification with Google to get the string called SID. You can rely on an external tool to connect with https and give you SID. If you do, https won't be required.

Cookie support is only required to pass to all pages the current SID, proof of identification. If are able to change add lines in headers, cookie support is not required anymore.

Google Reader API may require :

  • http client
  • GET and POST support
  • external tool to get SID (using https)
  • putting SID into header

Glossary

  • SID : Session ID. SID is generated each time you login to Google (any service). The SID is valid until you logout.
  • user ID : a 20 digits string used by google reader to identify a user. You don't really need to know it. You can always do things a way that user ID is not needed. Usually, when you need that information, just replace it by - and the user ID for current logged user will be used. The user ID never change for a user.
  • token : A token is a special 57 chars string that is used like a session identification, but that expire rather quickly. You usaully need a token for direct api calls that change informations. The token is valid for few minutes/hours. If API call fail (doesn't return OK), you just have to get antoher token.
  • client ID : A string that identify the client used. I suppose it's for logging/stat purpose, or perhaps to make some adjustement for some clients, but I doubt so. old GoogleReader interface use 'lens', new one use 'scroll'. The writer of this document use 'contact:name-at-host' for interactive test, and use string like 'pyrfeed/0.5.0' for the software pyrfeed in version 0.5.0 (like classical identification strings for unix softwares).
  • item/entry : Sometimes called item, sometimes called entry, the item is the base element of a feed. An item usally contain a text, a title and a link, but can contain other properties. An RSS/Atom aggregator aggregates items. (Note: item is the RSS term, while entry is the Atom term).

Identification

Note : According to Mihai Parparita in Google Reader Support Group ( http://groups.google.com/group/Google-Labs-Reader/browse_frm/thread/73a0aed708bcd005 ), "Authentication is one of the reason why the API hasn't been released yet". You should expect big changes before Google Reader release official API.

To login, you need to post with https on https://www.google.com/accounts/ClientLogin with the following POST parameters :

POST parameter name POST parameter value
service 'reader' (!)
Email your login
Passwd your password
source your client string identification (!)
continue 'http://www.google.com/' (!)

Of course, your login and your password are login and password you usually use to identify interactively to Google.

(!) : Those parameters are said to be optional ( http://code.google.com/p/pyrfeed/issues/detail?id=10 ). I didn't really tested. It's just how "browsers" identifies themselfs. Note that I consider source and service as a being informative parameters for google, so I feel like I need to provide them, event if they are not required. Note that I have no idea about what Google or the Google Reader team really think about that. Perhaps they prefer "nothing but a crafted information", or perhaps they don't care. Who knows...

There is no official rule your client string identification, see client ID in glossary for more informations.

The POST action will return you a text file, containing lines of the form :

key=value

You need to extract the value for the key named SID

You then have to add yourself a cookie (well, it look like Google doesn't add it itself) with the following properties :

name SID
domain .google.com
path /
expires 1600000000

If you don't have a http client API that support cookies, you can just add header lines that simulate this cookie in all other requests. This should be the only thing for which cookies are really needed.

The three layers for feed aggregators

When you're writting a feed aggregator, you need to write three different layers :

  • Layer 1 : The layer that parse feeds. It's not the easiest job. "But, it's just xml, it should be easy". It's not. It's just xml. It's just 10 differents and incompatible xml formats (9 RSS formats according to Mark Pilgrim and 1 Atom format). You also perhaps need to understand all non standard feeds that mix some features from differents standards.
  • Layer 2 : The database layer. Once you've parsed your feed, you need to store it in a database, and and interesting things like "items read", etc.
  • Layer 3 : The user interface.

Google Reader offer in fact acces to layer 1 only, or layer 1+2 or layer 1+2+3.

You can have acces to layer 1 only. Feeds are parsed by Google Reader, and Google Reader give you access to a new Atom feed that contains same data as the original feed, but always with the same output format : Atom.

You can have acces to layer 1+2. This documents purpose is about how to acces to layer 1+2 from Google Reader in order to create your own layer 3.

Of course, you have access to layer 1+2+3 because it's Google Reader's main product.

Url scheme

Except for identification process, all Google Reader url ressources start with http://www.google.com/reader/. We'll explain here direct subspaces of thoses urls.

URL prefix Will be refered as, in this document Description
http://www.google.com/reader/atom/ /atom/ All urls starting by this prefix return atom feeds. It's the (only?) way to acces to feed contents. This is the way to access layer 1 and layer 1+2.
http://www.google.com/reader/api/0/ /api/0/ This is the main API entry point. It's used for items/feeds modifications, like adding a Star, deleting a tag, etc. For those modification services, it return either "OK" or "". It's also used to consult some setting lists like list of feeds, list of tags, list of unread counts by feeds/tags, etc. For those read services, it returns an "object" that can be either json or xml that look like json. This is a layer 2 only zone.
http://www.google.com/reader/view/ /view/ All AJAX interface is done by /view/ urls. AJAX code use /atom/ and /api/0/ as sublayers to do the job. This is the way to access layer 3.
http://www.google.com/reader/shared/ /shared/ All shared pages use this prefix. You obviously don't need authentification to use those pages.
http://www.google.com/reader/settings/ /settings/ The AJAX application to configure all settings. Mainly manipulate informations from /api/0/. This part of layer 3.

Atom set of items

this section is about urls starting by http://www.google.com/reader/atom/

The Google Reader database contains a huge number of items. Some of them are in your reading list (understand, they are accessible in Google Reader for your account in "All items" section, and in your feeds/tags).

The only way to get information related to an item is to "query an atom set of items" that contain this item.

All items are or were included in feeds. One way to query items is to query the original feed.

Item are also associated to categories. tags/labels are categories, but also the "read" state is also a category.

Antoher way to query items is to query all items that are associated to a category.

Set of items suffix Description
feed/ url of a feed The url to query a specific feed. It's Google Reader way to access to layer 1 only. Note : This service is not related to an account and can be access without registration.
user/ user ID/ label/ label name This is the suffix to access to all items with a specific label
user/ user ID/ state/com.google/ state This is the suffix to access to all items with a specific state like read, starred, etc.

You can use - as your user ID, it will use the user ID for your currently identified account.

State name State meaning
read A read item will have the state read
kept-unread Once you've clicked on "keep unread", an item will have the state kept-unread
fresh When a new item of one of your feeds arrive, it's labeled as fresh. When (need to find what remove fresh label), the fresh label disappear.
starred When your mark an item with a star, you set it's starred state
broadcast When your mark an item as being public, you set it's broadcast state
reading-list All you items are flagged with the reading-list state. To see all your items, just ask for items in the state reading-list
tracking-body-link-used Set if you ever clicked on a link in the description of the item.
tracking-emailed Set if you ever emailed the item to someone.
tracking-item-link-used Set if you ever clicked on a link in the description of the item.
tracking-kept-unread Set if you ever mark your read item as unread.

If you need to query a set of items in an atom format, just query http://www.google.com/reader/atom/ followed by the set of items suffix.

For exemple, if you want to acces to Google Reader's rewritting of the feed http://xkcd.com/rss.xml , you can query http://www.google.com/reader/atom/feed/http://xkcd.com/rss.xml . This can be done whether you are identified or not. If you want to query all your last read items, you can query http://www.google.com/reader/atom/user/-/state/com.google/read .

Each atom set contains by default 20 items. You can change that, and other behaviour by adding parameters to the query.

GET parameter name python Google Reader API name parameter value
n count Number of items returns in a set of items (default 20)
client client The default client name (see client in glossary)
r order By default, items starts now, and go back time. You can change that by specifying this key to the value o (default value is d)
ot start_time The time (unix time, number of seconds from January 1st, 1970 00:00 UTC) from which to start to get items. Only works for order r=o mode. If the time is older than one month ago, one month ago will be used instead.
ck timestamp current time stamp, probably used as a quick hack to be sure that cache won't be triggered.
xt exclude_target another set of items suffix, to be excluded from the query. For exemple, you can query all items from a feed that are not flagged as read. This value start with feed/ or user/, not with !http:// or www
c continuation a string used for continuation process. Each feed return not all items, but only a certain number of items. You'll find in the atom feed (under the name gr:continuation) a string called continuation. Just add that string as argument for this parameter, and you'll retrieve next items.

Note : continuation has no meaning, it's just a string to help you find next items. You should not rely on its value to do anything else than that (even if this document will explain how that continuation is generated).

Exemple :

All the 17 first items items from xkcd.com main feed that are not read can be found on the url : http://www.google.com/reader/atom/feed/http://xkcd.com/rss.xml?n=17&ck=1169900000&xt=user/-/state/com.google/read

API

this section is about urls starting by http://www.google.com/reader/api/0/

There are two knids of API commands:

  • edit commands
  • list commands

The number 0 is probably the API version number. Using that number, it will allow Google Reader to change API while stile maintaining an old API for quite some time.

Edit API

To edit anything in the Google Reader database, you need a token (see glossary). To get a token, just go to http://www.google.com/reader/api/0/token . This url will return a string containing 57 chars. It's the token.

The token url takes optional GET arguments:

GET parameter name python Google Reader API name parameter value
ck timestamp current time stamp, probably used as a quick hack to be sure that cache won't be triggered.
client client The default client name (see client in glossary)

All edit commands use POST to retrieve information (note that GET won't work) but they also take a GET argument.

GET parameter name python Google Reader API name parameter value
client client The default client name (see client in glossary)

All edit commands will return either an empty string if failled, either the string "OK". If failed, your token has perhaps expires. You can just try to get a new token. If it still doesn't return OK, it's a failure.

Table of POST aguments for the subscription/edit edit call.

API call function POST parameter name python Google Reader API name parameter value
subscription/edit
s feed The subscription feed name, in the form feed/...
t title The subscription title, used when adding a new subscription or when changing a subscription name
a add A label to add (a label on a subscription is called a folder) in the form user/...
r remove A label to remove (a label on a subscription is called a folder) in the form user/...
ac action The actions to do. Know values are edit (to add/remove label/forlder to a feed), 'subscribe', 'unsubscribe'
token token The mandatory up to date token
tag/edit
s feed The tag/folder name seen as a feed
pub public A boolean string true or false. When true, the tag/folder will become public. When false, the tag/folder will stop being public.
token token The mandatory up to date token
edit-tag
i entry The item/entry to edit, in the form tag:google.com,2005:reader/item/... ( it's the xml id of the entry tag of the atom feed)
a add A label/state to add (a label on an item/entry is called a tag) in the form user/...
r remove A label/state to remove (a label on an item/entry is called a tag) in the form user/...
ac action The actions to do. Know value is edit (to add/remove label/forlder to a feed)
token token The mandatory up to date token
disable-tag
s feed The tag/folder name seen as a feed
ac action The actions to do. Know value is disable-tags (to remove a tag/folder)
token token The mandatory up to date token

Exemples :

To subscribe a new feed (for exemple http://xkcd.com/rss.xml), you can call:

http://www.google.com/reader/api/0/subscription/edit?client=contact:myname-at-gmail
with POST arguments : s=http://xkcd.com/rss.xml&ac=subscribe&token=here-put-a-valid-token
To add that feed in a folder (for exemple "comics"), you can call:
http://www.google.com/reader/api/0/subscription/edit?client=contact:myname-at-gmail
with POST arguments : s=http://xkcd.com/rss.xml&ac=edit&a=user/-/label/comics&token=here-put-a-valid-token

Open questions that needs to be fixed :

  • Are tag/edit and edit-tag just aliases ?
  • Why does removing a tag/folder doesn't take an action while every other calls take actions ?
  • Why is there several urls, it seems redundant with the action parameter ?

List API

All those calls can be used with GET requests.

API call function GET parameter name python Google Reader API name parameter value/API call description
tag/list Get the tag list and shared status for each tag.
output output The format of the returned output. may be 'json' or 'xml'
ck timestamp current time stamp, probably used as a quick hack to be sure that cache won't be triggered.
client client The default client name (see client in glossary)
subscription/list Get the subscription list and shared status for each tag.
output output The format of the returned output. may be 'json' or 'xml'
ck timestamp current time stamp, probably used as a quick hack to be sure that cache won't be triggered.
client client The default client name (see client in glossary)
preference/list Get the preference list (configuration of the account for GoogleReader).
output output The format of the returned output. may be 'json' or 'xml'
ck timestamp current time stamp, probably used as a quick hack to be sure that cache won't be triggered.
client client The default client name (see client in glossary)
unread-count Get all the information about where are located (in term of subscriptions and tags/folders) the unread items.
all all 'true' if whole subscriptions/tags are required. (TODO: Needs to check other values)
output output The format of the returned output. may be 'json' or 'xml'
ck timestamp current time stamp, probably used as a quick hack to be sure that cache won't be triggered.
client client The default client name (see client in glossary)

Viewer

this section is about urls starting by http://www.google.com/reader/view/

All url starting by http://www.google.com/reader/view/ are html pages that use AJAX code to show atom feeds found from http://www.google.com/reader/atom/.

You can append to the base url any set of items suffix to view only that set of items. Note however that GET parameters are not valid (in fact are ignored) for those urls.

You can browse directly all your items labeled "important" by going to http://www.google.com/reader/view/user/-/label/important

You can browse directly all items from xkcd main feed by going to http://www.google.com/reader/view/feed/http://xkcd.com/rss.xml even if you didn't subscribed to it (in which case there will be a button "Subscribe" on the top of the screen). Note however that if you're not identified, you'll browse the feed using the old interface (lens) and not the new on (scroll).

Misc

TODO: Text needs to be written TODO: mainly /share/

References


Comment by pricemonkeys, Jul 15, 2007

The api to mark the item as 'read' has slightly changed as on July 15, 2007. The name of the post parameter for token is 'T' and not 'token'.

Also to mark the item as 'read', you would need to pass parameter 'ac' with value 'edit-tags' and 's' with value of the feed url containing the item.

for e.g.

$req = POST $baseUrl, [
i => $guid, s => $url, a => 'user/-/state/com.google/read', ac => 'edit-tags', T => $token
];

Comment by pricemonkeys, Jul 15, 2007

The api to mark the item as 'read' has slightly changed as on July 15, 2007. The name of the post parameter for token is 'T' and not 'token'.

Also to mark the item as 'read', you would need to pass parameter 'ac' with value 'edit-tags' and 's' with value of the feed url containing the item.

for e.g.

$req = POST $baseUrl, [
i => $guid, s => $url, a => 'user/-/state/com.google/read', ac => 'edit-tags', T => $token
];

Comment by pricemonkeys, Jul 15, 2007

The api to mark the item as 'read' has slightly changed as on July 15, 2007. The name of the post parameter for token is 'T' and not 'token'.

Also to mark the item as 'read', you would need to pass parameter 'ac' with value 'edit-tags' and 's' with value of the feed url containing the item.

for e.g.

$req = POST $baseUrl, [
i => $guid, s => $url, a => 'user/-/state/com.google/read', ac => 'edit-tags', T => $token
];

Comment by pricemonkeys, Jul 15, 2007

The api to mark the item as 'read' has slightly changed as on July 15, 2007. The name of the post parameter for token is 'T' and not 'token'.

Also to mark the item as 'read', you would need to pass parameter 'ac' with value 'edit-tags' and 's' with value of the feed url containing the item.

for e.g.

$req = POST $baseUrl, [
i => $guid, s => $url, a => 'user/-/state/com.google/read', ac => 'edit-tags', T => $token
];

Comment by fitzgeraldsteele, Sep 05, 2007

Thanks for posting this! Seems like the API has changed a bit since Niall Kennedy's original article.

In playing with the API tonight, it seems like you have to be logged on in order to get any feeds from GReader...even the http://www.google.com/reader/atom/feed/http://xkcd.com/rss.xml link above seems to require that you are logged in. Has anyone else noticed the same thing?

Comment by 127.0.0.69, Sep 12, 2007

From the doc, I can't find a way to get the list of feeds subscribed... is that possible?

Comment by 127.0.0.69, Sep 12, 2007

From the doc, I can't find a way to get the list of feeds subscribed... is that possible?

Comment by 127.0.0.69, Sep 12, 2007

From the doc, I can't find a way to get the list of feeds subscribed... is that possible?

Comment by 127.0.0.69, Sep 12, 2007

From the doc, I can't find a way to get the list of feeds subscribed... is that possible?

Comment by 127.0.0.69, Sep 13, 2007

Sorry for duplicates comments. System bug.

I now know how to get the list of feeds subscribed... It was changed to: http://www.google.com/reader/api/0/subscription/list

The list of unread items count was also changed to: http://www.google.com/reader/api/0/unread-count?all=true

Unfortunately I still can't find a way to get the next 20 items after the first fetch... Maybe is through continuation POST var?

Comment by 127.0.0.69, Sep 13, 2007

Sorry for duplicates comments. System bug.

I now know how to get the list of feeds subscribed... It was changed to: http://www.google.com/reader/api/0/subscription/list

The list of unread items count was also changed to: http://www.google.com/reader/api/0/unread-count?all=true

Unfortunately I still can't find a way to get the next 20 items after the first fetch... Maybe is through continuation POST var?

Comment by 127.0.0.69, Sep 13, 2007

I seem to be misunderstanding some stuff... I checked, the continuation is used to get the next items (just like said in the doc). Thanks for the wiki.

Comment by graybot, Sep 14, 2007

note that ck (timestamp) is the standard unix timestamp, with the addition of milliseconds, so instead of 1189800875, it would be 1189800875112

Comment by graybot, Sep 14, 2007

for atom items, the get parameter r (sort order) can also have the value "n" which seems to be a synonym for "d". so "o" is oldest first, "n" is newest first, "d" is descending.

Comment by benamor.karim, Sep 20, 2007

Is there a way to filter a feed searching for a word? something like:

http://www.google.com/reader/view/user/-/label/important/#search/find_my_word

Comment by benamor.karim, Sep 20, 2007

Is there a way to filter a feed searching for a word? something like:

http://www.google.com/reader/view/user/-/label/important/#search/find_my_word

Comment by scruffyben, Dec 08, 2007

If I pass in the contents of <gr:continuation> as a parameter (c=...), it does jump me down the feed, but always to the same point (maybe post number 40).

Also, if i use n as a parameter it doesn't work for values over 9.

Are these bugs, or am I doing something wrong?

Comment by singpolyma, Jan 10, 2008

token is actually T= not token= remember it is s=feed/FEEDURL not just s=FEEDURL

Comment by glennmarcus, Mar 25, 2008

What about http://www.google.com/reader/public/atom/user/<uid>/label/<label>

This is the pure RSS atom feed of any tags you make public. It only returns the last 20 entries of the feed. Is there a way to make it return all the entries?

Comment by tubo.he, Mar 26, 2008

How can I get a URI like "https://www.google.com/reader/public/atom/feed/<feed URI>"? Or "http://www.google.com/reader/public/atom/feed/<feed URI>"? Is this structure just like "/reader/atom/feed/<feed URI>" that is used to request any feed from google reader system? If so, is there any fresh time of google reader system about this <feed URI>? Or fetch the content from <feed URI> and send it to the client just when user request it?

Comment by arnstein87, May 10, 2008

There seems to be lots of other API changes too. For example, for adding a subscription, google reader uses http://www.google.com/reader/api/0/subscription/quickadd?client=myclient with postdata as quickadd=<URL>&ac=subscribe&T=<TOKEN>

I think they might have changed more, and this document might need reviewing.

Comment by lechtitseb, Jun 03, 2008

I'm wondering if they're planning to release an official API someday :(. I'm working on a little Java program to manipulate my unread items, but it's quite painfull right now...

Comment by arnstein87, Jun 04, 2008

To get feeds beyong 20 feeds pass n=<numbertoretrieve> as GET request. Unfortunately I didn't figure out a way to start the feeds from a given number.

For example: http://www.google.com/reader/atom/feed/http://xkcd.com/atom.xml?n=20

Comment by lechtitseb, Jun 04, 2008

I'm working on an unofficial Java API for Google Reader based on this page's information.

Comment by sancho, Jun 06, 2008

Requierements is spelled requirements

Comment by thomas.a.meier, Jun 10, 2008

Is there any way to get the specific extensions in each feed? I'd like to be able to view the original itunes extensions through Google Reader because they keep history, but it seems like they strip them out; i.e. it's a bare-bones atom feed.

Comment by swetadri.iitm, Jun 12, 2008

Is there any way to login in google-reader account by java program only?Means from code, not from google-reader homepage.Ia m sending "Email" and "Passwd" as post parameter to https://www.google.com/accounts/ClientLogin.Then I am getting SID and LSID.Then I am dumoing cookie.But,its not taking setDomain(".google.com") method. What to do? I want to be logged in via code.IS therer any mistake I am doing?Plz help!!!

Comment by lechtitspam, Jun 14, 2008

@swetadri: I'm currently working on it, if you want more info and/or help me, you can contact me at lechtitseb at gmail . com

Comment by milobird, Jun 19, 2008

The "xt" parameter seems to work only for excluding read items. It seems to completely ignore other states, labels, or feed stream IDs beginning "feed/".

Does anyone have a workaround for this?

Comment by scarvel8, Jul 03, 2008

I have made my own java based google reader api. Theres no documentation, and it is incomplete, but it may be useful for someone. http://www.caip.rutgers.edu/~scarvel/grapijava/

Comment by swetadri.iitm, Jul 08, 2008

thanks to scarvel8...ur api is useful to me...

Comment by swetadri.iitm, Jul 10, 2008

scarvel8, did you do the same thing for subscribtion via my yahoo or bloglines?if yes, please let me know

Comment by scarvel8, Jul 10, 2008

No I haven't, although if I get some free time I will look into it. I am also working on other options not listed in this document, such as being able to load search results. I should have a more complete API up in the next week or two.

Comment by swetadri.iitm, Jul 10, 2008

ok..if you do for yahoo rssfeeds, plz tell me...

Comment by ForeverZeroRO, Jul 17, 2008

I am trying to access this url with an XMLHttpRequest: http://www.google.com/reader/atom/user/-/state/com.google/broadcast

However, the responseText is a Google error page which says the following: "Further action needs to be taken by your user agent in order to fulfill the request. "

The script goes through a PHP proxy so it can go cross domain. Does anyone know what information Google Reader requires that would fix this error?

Comment by franssauermann, Jul 17, 2008

Great article! I want to export my google reading list, and a step is to input it into a feedburner feed for further processing. I could not get Google to export the feed, with the correct userID: http://www.google.com/reader/atom/user/123456789123456789123456789/state/com.google/reading-list Is there authentication requirements?

Comment by franssauermann, Jul 22, 2008

Ok.. answered my own question. I tried a GET with https://www.google.com/accounts/ClientLogin?service=reader&Email=myusername&Passwd=mypassword and got the authentication requirements parameters

Comment by ladyfaa, Jul 29, 2008

Hi thanks for the post.Nice blog.Now this blog is in my favourite bookmark pages. http://www.squidoo.com/papershredderarticles

Comment by ForeverZeroRO, Jul 31, 2008

I out together a very small program that shows a basic way of grabbing GET data from Google Reader with Java. I commented it up so most questions should be answered. Note this is VERY basic, and just intended for people looking for information on how to get started.

http://www.foreverzero.org/Process.java

Comment by mdesaro, Jul 31, 2008

Has anyone been able to successfully implement the continuation parameter for getting more feed items from a feed? I cant seem to get it to work. The url I create I can put in a browser address bar and it works fine but when I hit it from a server (CURL) it always shows the first n items.

Comment by mdesaro, Jul 31, 2008

Also, I cant seem to get any of the xt (exclude) links to work. Has anyone pulled this off?

(http://www.google.com/reader/atom/?n=4&xt=user/-/state/com.google/read)

Comment by dfinkler, Aug 17, 2008

i can read N items from a feed.. i am currently limited by heap size only, yay

Comment by dfinkler, Aug 17, 2008

i can also query for number of unread items but have no implemented (in java) the ability to mark items as read.. any advice?

Comment by beglen, Aug 19, 2008

I can't make it retrieve more than 999 items from a given feed. Any ideas how I might get more than that?

(I have a few years' worth of friends' facebook status updates cached in Reader, and would love to be able to export them all! http://infoclarity.blogspot.com/2008/06/hidden-in-words.html)

Thanks for the great tips.

Comment by robertgriffo, Sep 04, 2008

Ok, you can probably tell I'm a complete noob at this from my question but here it goes. I'm just trying to make a very simple bash shell script using curl to get my unread count. I can view the data I want just fine when I open this link in safari (http://www.google.com/reader/api/0/unread-count?all=true) and I can view the source and see exactly what I'd like to extract. However, when I use curl in my shell script it doesn't work. I'm assuming I have to login as described at the beginning of the article to access this data using curl. My stupid question is this: is it safe/secure to include my user name and password in this url ( https://www.google.com/accounts/ClientLogin?service=reader&Email=myusername&Passwd=mypassword) in a shell script? Any suggestions would be a big help. Thanks!

Comment by pinowsky, Oct 04, 2008

For doing any operation which requires authentication, you would need to provide two tokens:

SID Authentication token or T token (do not mix up this token with the Auth token you get by authenticating against Google by ClientLogin?)

SID (session ID) is a session token. There are also two ways of fetching this token:

If you have a browser (i.e Firefox) opened and already logged in any Google site, a valid SID token would be stored inside your browser. Firefox stores session tokens inside session_store.js file. In conclusion, search for the SID inside session_store.js if there is any google session opened inside your Firefox.

Authentication against Google reader service using ClientLogin? mechanism. Google reader service codename is 'reader'. ClienLogin? mechanism is fully documented by Google (just google it). ClientLogin? mechanism returns three tokens, one of them is SID (session token).

Once you got a valid SID token, then you need to retrieve

Once you get a valid SID token, do a GET request to the following URL to get a valid T token.

http://www.google.com/reader/api/0/token

This request should be composed by adding SID as a Cookie.

Once you get both tokens, SID and T, you can successfully perform any Google Reader operations which require authentication (pass these two values as cookies)

So answering the question above, how to compose a valid curl command to fetch a list of unread elements:

First, get a valid SID token:

curl https://www.google.com/accounts/ClientLogin -d Email=just_your_username_here_without_at_gmail_dot_com -d Passwd=your_password_here -d source=Google-cURL-Example -d service=reader

Response: Auth=XXX SID=DQAAAH0AAAC0YHom0L5LDq10xGnbQK_O7OLiX3Qrou4XeA6P469shoM1goEFQT_zVn8YxDV38Y5v3mGJlhSzJuz5xLPqpKEM0Wedks-ak7LLpNjO7dZw779ljOQrC-2UCYFjiktJcfXmof7WeZs7O0SCNCQgPSKaENJ6FBTeDBeQLahUUrajrg LSID=XXX

Once you get a valid SID, request a T token:

curl -s -X GET http://www.google.com/reader/api/0/token --header "Cookie: SID=DQAAAH0AAAC0YHom0L5LDq10xGnbQK_O7OLiX3Qrou4XeA6P469shoM1goEFQT_zVn8YxDV38Y5v3mGJlhSzJuz5xLPqpKEM0Wedks-ak7LLpNjO7dZw779ljOQrC-2UCYFjiktJcfXmof7WeZs7O0SCNCQgPSKaENJ6FBTeDBeQLahUUrajrg"

Response:

kArWxxwBAAA.vegUbtUjv2Vvf_HKWlwjIA.QfhP1LoSb5ghYPz_AbOG_Q

Once you get a valid T token, perform any operation you want against Google Reader, for instance, retrieve your list of feeds

curl -s -X GET http://www.google.com/reader/api/0/unread-count?all=true --header "Cookie: SID=DQAAAH0AAAC0YHom0L5LDq10xGnbQK_O7OLiX3Qrou4XeA6P469shoM1goEFQT_zVn8YxDV38Y5v3mGJlhSzJuz5xLPqpKEM0Wedks-ak7LLpNjO7dZw779ljOQrC-2UCYFjiktJcfXmof7WeZs7O0SCNCQgPSKaENJ6FBTeDBeQLahUUrajrg; T=kArWxxwBAAA.vegUbtUjv2Vvf_HKWlwjIA.QfhP1LoSb5ghYPz_AbOG_Q" | tidy -xml -indent -quiet

Comment by uche.ogbuji, Oct 31, 2008

Following the curl breadcrumbs of pinowsky (thanks!) I worked up the following Python code to use Google Reader to convert feeds to Atom:

http://wiki.xml3k.org/Amara/Recipes/Google_Web_feed_atomizer

Comment by AlexeiSergeev, Nov 12, 2008

From now it seems like I need to be logged in to access atom/feed/somefeedurl?

Comment by rlstracker, Nov 12, 2008

I can't use command-line URL-fetchers (like 'wget' or 'GET') successfully when trying to access the following URL: http://www.google.com/reader/atom/feed/http://xkcd.com/rss.xml

They don't return XML data, but rather an HTML page telling me to log in. Is Google restricting access to particular user-agents (browsers)?

Comment by taka.atsushi, Nov 12, 2008

Google Reader has feed translation, introduced 2008-11-11.

That's accessible by the parameter/key pair of "trans=true"

ex. http://www.google.com/reader/atom/feed/SOME_FEED_URL?trans=true

the above translates to the language of your setting with Google Reader.

I don't know if you can make it translate to languages of your choice just by varying a parameter.

Comment by katapulp, Nov 25, 2008

Is "edit-tag" still working?

I got a "400 client error" when I try to add a label to a specific post of my favorite list. I got a valid SID and Token, but for exemple this URL is not working: http://www.google.com/reader/api/0/edit-tag?ac=edit&i=tag:google.com,2005:reader/item/041fa449c5de72c9&a=user/-/label/test&token=97xa1B0BAAA.RDpLb8-l3NMfqpaw0vYq-g.JcgYUQXFh9E6MmkLNIpwEw

Am I missing something?

Comment by mariano.kamp, Dec 13, 2008

Hi,

I am wondering how to sync with GoogleReader?? for offline reading? I want the latest 10 entries that I haven't seen before, e.g. r=d (date descending), n=100, ot=<timestamp of last sync>. But you say above that specifying ot only works with r=o. ;-(

Cheers, Mariano

Comment by ThrashingStick, Dec 18, 2008

Hi Mariano -- What you're going to want to do is use the "xt" (exclude target) parameter to exclude read items in your query. Look for "xt" above.

Comment by mariano.kamp, Dec 21, 2008

Hi TrashingStick?, I appreciate very much that you took the time to post an answer. I thought nobody would ;-(

But this would not help me really. It is not the same to have donwloaded an item and have read it. So I download a couple of items to a mobile device, read some of them, but then don't want to download the unread items all over again every time I sync. It is also not an option to mark them as read anyway and keep a separate read state on the client. This would make the items marked read for the online reader also.

Any more ideas?

Comment by jesuscheung, Dec 28, 2008

the start_time parameter no longer (or never) works.

no matter what start_time i set, whether r=o or r=n, the oldest feed item returned is within this month.

oh well. if anyone tries to grap all the items. the way is to set n very very big so that it covers all the items.

Comment by shabda.shabda, Dec 29, 2008

Will somebody pl tell me - 1. how to mark an item as read (using these api) 2. how to mark many items as read (using theser api)

I tried whatever has been said above.......however not getting it right. Pl explain with an example.

Thanks a ton in advance -shabda

Comment by jackphelps, Feb 05, 2009

Does anyone know how to solve this...?

I'm trying to roll my own aggregator by running feeds through the API to normalize the contents. Works great for most feeds ("http://www.google.com/reader/atom/feed/#{feed.url}"). However, some feeds use url parameters to deliver their contents... example: "http://img.perezhilton.com/?feed=rss2". The API sees this and thinks the feed address is just "http://img.perezhilton.com/", and that the "?feed=rss2" is a parameter for IT, rather than the feed's server. Escaping the ? does not work... anyone have any clues?

Thanks to all for the awesome work figuring this out.

Comment by Sesarr.bg, Feb 28, 2009

jackphelps, try urlencoding the whole url:

http://www.google.com/reader/atom/feed/http%3A%2F%2Fimg.perezhilton.com%2F%3Ffeed%3Drss2

this seems to work :). Good luck with your project

Comment by koonuf, Mar 02, 2009

I'm getting 401 (Unauthorized) HTTP error, when trying to call "edit" API methods. I've tried to attach "T" token both in post request and as cookie to no avail. Does anyone else get the same error?

Comment by michael.ayvazyan, Mar 02, 2009

I'm have the same problem (401 (Unauthorized))

Comment by AlexeiSergeev, Mar 11, 2009

Google don't allow to remove "user/-/state/com.google/read", and I failed to add "user/-/state/com.google/kept-read". Any tips on how to mark article "unread" now?

Comment by MekkMekk, Mar 20, 2009

Thank you very much for this analysis, it was very helpful.

Here is my small tool written using Reader API (and some python code): managing subscriptions as a text file

Comment by wayne.culbreth, Mar 23, 2009

katapulp - did you have any luck? I'm having the same issue. I've presented the i, s, & a arguments in every way I can imagine (in the url, as data in the post, URL encoded, not URL encoded) and the same with SID and token, and I always get a 400 or 401 error. Any one here have any luck editing tags? I can read data no problem, I just can't modify.

Comment by karthik085, Apr 02, 2009

Hi, For all shared items, how can I get the list of tags for each shared item? I have been trying with the above api and so far unsuccessful. Any suggestions are appreciated. Thanks.

Comment by boldakov, Apr 15, 2009

To catapulp and wayne.culbreth:

I have a working 'edit-tag' feature of marking entries as read in the following way:

Post to url: http://www.google.com/reader/api/0/edit-tag?client=- Post body: "i="+entryId+"&a=user/-/state/com.google/read&ac=edit&T="+token

Other combinations of T->token, ac=edit->ac=edit-tags, adding s=feedURL and so on come to 400 error from Google.

Comment by ionutz.posea, Apr 16, 2009

Hello guys ,

I am planning to write an application that simulates a Feed Reader and manager and I decided to write it in SIlverlight (it sounded interesting and I hope I will learn a lot).

My first problem was somehow to "generalize" the feeds brought into the application. After some research I found out Google Reader offers the posibility to access their first layer ( parsing layer) and in this way I could get the feed in atom format for any feed.

(using http://www.google.com/reader/atom/feed/[URL] command)

Ok ,things were clear until here .I already knew that for an SIlverligt appication to exist the posibility to extract some data from another location than it's domani ,that data site should have a crossdomain.xml file in the root of the site.

My thought was first that Google has something like this ,I also was enthusiastic when found reply to crossdomain.xml. But disappointment come soon because on a closer look the xml file looks like :

<?xml version="1.0"?> <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/ dtds/cross-domain-policy.dtd"> <cross-domain-policy>

<site-control permitted-cross-domain-policies="by-content-type" />
</cross-domain-policy>

So my first idea was to use a proxy to access this link ,I am new in this technology and tried some solutions:

SIlverlight can extract for example any data through a proxy ,for example this works: http://al.cloudapp.net/proxy.ashx?http://rss.cnn.com/rss/edition.rss ,it extracts the direct feed from cnn site even if they don't have a crossdomain.xml file.

My next step was to generalize the feed through Google Reader :

http://al.cloudapp.net/proxy.ashx?http://www.google.com/reader/atom/feed/http://rss.cnn.com/rss/edition.rss ,but this solution failed ,I also tried with different proxies and no success.

My questions would be:

1.Why Google has this crossdomain.xml file and not a more permissive one? Could it be possible to modify this crossdomain.xml so that Silverlight application can access this API?

2.If 1 is not possible does anyone have a better solution ,I feel I am very close and maybe it may work through a proxy and I am doing something wrong?

3.Anyone else have any other ideas?

Thanks a lot, Ionut

Comment by garyhurtz, May 03, 2009

Hello. Just found this and have only begun digging in, but my first simple test is failing and it seems to be a "mad-made" issue. Google Reader shows that I have 84 unread items, yet the following code only returns 20 entries:

xmlfeed = gr.get_all()
print xmlfeed.get_title()
for entry in xmlfeed.get_entries():
    print entry

I see a 'count' parameter in ATOM_ARGS which may be used to limit the number of items (?) and "20" is a suspiciously convenient and round number, but I dont see any reference to 20 in the code... Is the response limited to 20 items?

Comment by curtis.herbert, May 06, 2009

Has anyone looked into emulating the ability of the bookmarklet they release (http://googlereader.blogspot.com/2008/05/share-anything-anytime-anywhere.html). It allows you to share an item even if it isn't in one of your feeds. Would be nice to be able to duplicate this in the code too.

Comment by chadotter, May 13, 2009

Mine works for a little while, but then I get a 302 redirection and the message "Further action needs to be taken by your user agent in order to fulfill the request." After some period of time (I'm not sure how long yet) it will start working again.

If anyone aware of a limit to how often you can access the API during a period of time. I always get to a similar point (>100 I think) before getting the redirection.

Comment by lefts...@me.com, May 21, 2009

I've already queried atom feeds from it several thousand times in testing my app. Seems to be no problem there.

Comment by boldakov, Jun 02, 2009

Does anybody know how to eliminate duplicates of entries which google returns sometime with the http://www.google.com/reader/atom/ API? This often happens when the RSS creators update entry, but the URL or id of the entry is changed. The same feed explored with Google Reader web interface doesn't contain duplicates, which appear with Reader API. While Google Reader is based on the GoogleReader? API it should be possible to avoid duplicates with API too.

Comment by monkiki, Jun 03, 2009

How can I get a list of unread news (with the title)?

Comment by bojerko, Jun 10, 2009

Trying to make edit tag work. I've got the data to be sent by using Firebug in Firefox and using online Google Reader. The result is return of "Invalid stream name." Anybody knows what that means?

Comment by abdulrahman86, Jun 23, 2009

Hey i am getting a 400 error when i try to add a subscription list to google reader. Here is what I am doing

url = "http://www.google.com/reader/api/0/subscription/edit?client=-"

I set my http request url to this

and pass the following post parameters

postRequestPayload=feed/http://xkcd.com/rss.xml&ac=subscribe&T="+token.

I have also tried token instead of T and also tried client=scroll in my url but I still get the 400 error. Please help.

Comment by cubegames, Jun 27 (6 days ago)

The official Google Reader desktop gadget uses the API, so accurate API information can be gathered from it: http://code.google.com/p/google-reader-gadget/


Sign in to add a comment
Hosted by Google Code