有没有更好的方法可以从您的 gData 联系人中获取特定的 Id,ContactGroupEntry
而无需检索和遍历整个列表?
// contactsService has been properly initialized...
// hunting for the groupNameId corrisponding to the plaintext groupName
final URL url = new URL("http://www.google.com/m8/feeds/groups/default/full");
String groupNameId = null;
ContactGroupFeed f = contactsService.getFeed(url, ContactGroupFeed.class);
int totalResults = f.getTotalResults();
List<ContactGroupEntry> list = f.getEntries();
while (list.size() < totalResults) {
Query q = new Query(url);
q.setStartIndex(f.getStartIndex() + f.getItemsPerPage());
q.setMaxResults(200);
f = this.contactsService.query(q, ContactGroupFeed.class);
list.addAll(f.getEntries());
}
for(ContactGroupEntry g : list) {
if (groupName.compareTo(g.getPlainTextContent()) == 0) {
groupNameId = g.getId();
break;
}
}
// return groupNameId