3.0 Java Documentation - Retrieving all contacts

20 views
Skip to first unread message

NMAGOCIO

unread,
Nov 18, 2009, 11:22:16 PM11/18/09
to Google Contacts API
I am posting this to help clarify and update the documentation for:
http://code.google.com/apis/contacts/docs/3.0/developers_guide_java.html#retrieving_without_query
I think this section was a re-post of the 2.0 guide and it does not
work like that anymore.
ContactFeed resultFeed = myService.getFeed(feedUrl,
ContactFeed.class);
will only get you the first page (25) entries.

How it works now:

First create a helper method:

public static ContactFeed retrieveAllContacts(ContactsService
myService, URL metafeedUrl)
throws
AppsForYourDomainException, ServiceException, IOException {

ContactFeed allContacts = new ContactFeed();
ContactFeed currentPage;
Link nextLink;
//String [] oAuthId = metafeedUrl.toString().split("\\?"); //un-
comment if using OAuth

do {
currentPage = myService.getFeed(metafeedUrl, ContactFeed.class);
allContacts.getEntries().addAll(currentPage.getEntries());
nextLink = currentPage.getNextLink();
if (nextLink != null) {
//metafeedUrl = new URL(nextLink.getHref() + "&" + oAuthId
[1]); //un-comment If using OAuth
feedUri = new URL(nextLink.getHref()); //comment this line if using
OAuth
}
} while (nextLink != null);

return allContacts;
}
NOTE! Read the inline OAuth comments

Now just replace the old line and you get all the entries.
ContactFeed resultFeed = retrieveAllContacts(myService, feedUrl);

Hope this helps.
Reply all
Reply to author
Forward
0 new messages