如何使用分页来检索Google文档?

时间:2011-09-07 14:39:52

标签: java google-docs google-docs-api

我使用Java客户端库通过分页接收谷歌文档信息。 我的代码:

private static final String URL_STRING = "https://docs.google.com/feeds/default/private/full/";

public List<DocumentListEntry> getAllDocs() throws Exception {
    URL feedUri = new URL(URL_STRING);
    DocumentQuery query = new DocumentQuery(feedUri);
    query.setMaxResults(2);
    query.setStartIndex(1);
    DocumentListFeed feed = client.getFeed(query, DocumentListFeed.class);
    return feed.getEntries();
}

处理条目:

List<DocumentListEntry> docList = gDocumentsRetriever.getAllDocs();
for (DocumentListEntry entry : docList) {
    processEntry(oAuthToken, gDocumentsRetriever, entry);
}

我得到两个条目。但是如果我改变了

query.setStartIndex(1);

query.setStartIndex(3);

我得到两个条目。

1 个答案:

答案 0 :(得分:0)

我发现如何实现这个问题: http://code.google.com/apis/documents/docs/3.0/developers_guide_java.html#pagingThroughResults

对于其他服务,它以同样的方式实现。

相关问题