Java GData Spreadsheets API 获取 Feed 失败

发布于 2024-10-12 17:54:20 字数 1112 浏览 7 评论 0原文

我正在尝试通过文档的密钥获取特定文档。我按照此处的说明进行操作: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

东京女 2024-10-19 17:54:20

对于返回 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

吃→可爱长大的 2024-10-19 17:54:20

我知道这是一项令人讨厌的黑客工作,但因为我找不到任何其他解决方案,所以我最终下载了 com.google.gdata.wireformats.input.AtomDataParser 的源代码,创建了一个 Reader 对象包装器,将预期的标签注入到流中它正在解析。我将 AtomDataParser 代码中的这一行更改

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

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

:如果您曾经将 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:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文