public List<Contact> getContacts() throws ContactsException {
ContactsService service = new ContactsService("contactlist");
try {
service.setUserCredentials(email, password);
} catch (AuthenticationException e) {
throw new ContactsException("login failed", e);
}
try {
URL feedUrl = new URL("http://www.google.com/m8/feeds/contacts/" + email + "/full");
Query query = new Query(feedUrl);
query.setMaxResults(Integer.MAX_VALUE);
ContactFeed resultFeed = service.query(query, ContactFeed.class);
List<Contact> contacts = new ArrayList<Contact>();
for (ContactEntry entry : resultFeed.getEntries()) {
for (Email email : entry.getEmailAddresses()) {
String address = email.getAddress();
String name = null;
if (entry.hasName()) {
name = entry.getName().getFullName().getValue();
} else {
name = getUsername(address);
}
contacts.add(new Contact(name, address));
}
}
return contacts;
} catch (Exception e) {
throw new ContactsException("gmail protocol has changed", e);
}
}