从gdata API读取文档的内容? [英] Reading a document's content from the gdata API?

查看:87
本文介绍了从gdata API读取文档的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java库来访问gdata api.我只希望能够打印文档的内容.我设置了项目以列出Feed中的所有文档,现在我有了一个文档列表,我想打印其内容:

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();
}

似乎我们应该从条目中获取URL,然后自己读取URL上的内容.我发现一则帖子指出,这就是我们获取该网址的方式:

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();

但是当我尝试从中读取内容时,我收到了一个HTML响应,说此内容已移动".我读到这是因为我们必须验证我们的http-read方法,但是我不确定该怎么做.真的没有内置的方法可以做到这一点吗?

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?

谢谢

推荐答案

MediaContent content = (MediaContent) entry.getContent();
MediaSource source = docService.getMedia(content);
InputStream in = source.getInputStream();

这篇关于从gdata API读取文档的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆