javagoogle-sheetsgdata-api

Java GData Spreadsheets API failing on getting Feed


I'm trying to get a specific document by the key of the doc. I'm following the instructions here: https://code.google.com/apis/spreadsheets/data/3.0/reference.html#ConstructingURIs

I get the key from the URL: https://spreadsheets.google.com/ccc?key=0Aoz...mcmc&hl=en#gid=0

URL feedUrl = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full/0Aoz...mcmc");
SpreadsheetFeed feed = _service.getFeed(feedUrl, SpreadsheetFeed.class);
_entry = feed.getEntries().get(0);

It gives me the following exception:

Exception in thread "main" com.google.gdata.util.ParseException: [Line 1, Column 165]
Invalid root element, expected (namespace uri:local name) of (http://www.w3.org/2005/Atom:feed),
    found (http://www.w3.org/2005/Atom:entry

The exception doesn't really make a whole lot of sense. I guess it wants the tag to be the root but it's getting . If I go to the URL I'm using for feedUrl then I get the XML document I want (has the name and all that of the document I'm aiming for). I don't see what I'm doing wrong here and I can't find anything online that has been able to help me.

Anyone see what I'm doing wrong?


Solution

  • I know it's a nasty hack job, but because I couldn't find any other solution I ended up downloading the source for com.google.gdata.wireformats.input.AtomDataParser, creating a Reader object wrapper that injected the expected tag into the stream it was parsing. I changed this line in the AtomDataParser code:

    feedResult.parseAtom(inProps.getExtensionProfile(), inputReader);
    

    to:

    if(feedResult instanceof SpreadsheetFeed) {
        feedResult.parseAtom(inProps.getExtensionProfile(), new utils.ReaderWrapper(inputReader));
    } else {
        feedResult.parseAtom(inProps.getExtensionProfile(), inputReader);
    }
    

    This would obviously not work if you were ever using the SpreadsheetFeed with any other URLs, but it works for what I'm doing.