Java GData Spreadsheets API 获取 Feed 失败
我正在尝试通过文档的密钥获取特定文档。我按照此处的说明进行操作:https://code。 google.com/apis/spreadsheets/data/3.0/reference.html#ConstructingURIs
我从以下网址获取密钥: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);
它给了我以下异常:
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
该异常并没有多大意义。我猜它希望标签成为根,但它正在变得 .如果我转到用于 feedUrl
的 URL,那么我会得到我想要的 XML 文档(具有我想要的文档的名称和所有内容)。我不明白我在这里做错了什么,我在网上找不到任何可以帮助我的东西。
有人看到我做错了什么吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于返回 feedtypes,feedUrl 应为“https://spreadsheets.google.com/feeds/spreadsheets/private/full/”
the feedUrl should be "https://spreadsheets.google.com/feeds/spreadsheets/private/full/" for return feedtypes
我知道这是一项令人讨厌的黑客工作,但因为我找不到任何其他解决方案,所以我最终下载了 com.google.gdata.wireformats.input.AtomDataParser 的源代码,创建了一个 Reader 对象包装器,将预期的标签注入到流中它正在解析。我将 AtomDataParser 代码中的这一行更改
为
:如果您曾经将 SpreadsheetFeed 与任何其他 URL 一起使用,这显然不起作用,但它适用于我正在做的事情。
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:
to:
This would obviously not work if you were ever using the SpreadsheetFeed with any other URLs, but it works for what I'm doing.