Search code examples
javagoogle-docsgoogle-docs-api

How to use paging for retrieving Google docs?


I wand to receive google docs info with paging using Java Client Library. My code:

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

And processing entries:

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

I get two entries.But if I change

query.setStartIndex(1);

to

query.setStartIndex(3);

i get same two entries.


Solution

  • I found how this issue can be realized: http://code.google.com/apis/documents/docs/3.0/developers_guide_java.html#pagingThroughResults

    For other services it realizes in the same way.