Reading a document's content from the gdata API?

走远了吗. 提交于 2019-12-24 19:46:45

问题


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


回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/2197487/reading-a-documents-content-from-the-gdata-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!