从 gdata API 读取文档内容?
我正在使用 java 库来访问 gdata api。我只想能够打印文档的内容。我将项目设置为列出提要中的所有文档,现在我有了文档列表,我想打印其内容:
for (DocumentListEntry entry : feed.getEntries()) {
// Ok, how do we print the doc's contents now?
entry.getContents();
}
看起来我们应该从条目中获取 URL,然后读取 URL 处的内容我们自己。我发现一篇文章指出,这就是我们获取该 URL 的方式:
MediaContent content = (MediaContent)entry.getContent();
String url = content.getUri();
但是当我尝试从中读取内容时,我收到一个 html 响应,上面写着“此内容已移动”。我读到这是因为我们必须验证我们的 http-read 方法,但我不知道如何做到这一点。难道真的没有内置的方法可以做到这一点吗?
谢谢
I'm using the java library to access the gdata api. I just want to be able to print the contents of a document. I setup my project to list all the docs in my feed, now that I have a document listing, I want to print its contents:
for (DocumentListEntry entry : feed.getEntries()) {
// Ok, how do we print the doc's contents now?
entry.getContents();
}
It looks like we're supposed to get the URL from the entry, then read the contents at the URL ourselves. I found a post stating that this is how we get that URL:
MediaContent content = (MediaContent)entry.getContent();
String url = content.getUri();
but when I try to read from it, I get an html response saying 'this content has moved'. I read that this is because we have to authenticate our http-read method, but I'm not sure how to do that. Is there really no built-in way to do this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没关系,使用它,谢天谢地,它已包含在这些类中:
http://code.google.com/p/gdata-java-client/source/browse/#svn/trunk/java/sample/docs
Nevermind, use this, it's wrapped up in these classes for you, thankfully:
http://code.google.com/p/gdata-java-client/source/browse/#svn/trunk/java/sample/docs