List<ContactModel> result = new ArrayList<ContactModel>();
try {
// myself
ContactModel contactModel = new ContactModel();
contactModel.setEmailAddress(loginInfo.getEmailAddress());
contactModel.setNikeName(loginInfo.getNickname());
contactModel.setAlbumList(loadAlbum(loginInfo.getNickname()));
result.add(contactModel);
// get firends
ContactsService service = new ContactsService("Kirin-App");
if(this.getThreadLocalRequest().getSession().getAttribute("sessionToken") != null){
service.setAuthSubToken(this.getThreadLocalRequest().getSession().getAttribute("sessionToken").toString());
}
URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/full");
ContactQuery contactQuery = new ContactQuery(feedUrl);
contactQuery.setMaxResults(1000);
ContactFeed resultFeed = service.getFeed(contactQuery, ContactFeed.class);
for (ContactEntry contactEntry : resultFeed.getEntries()) {
if (contactEntry.hasEmailAddresses()) {
for (Email email : contactEntry.getEmailAddresses()) {
if (email.getAddress().contains("gmail.com") && !email.getAddress().equals(loginInfo.getEmailAddress())) {
contactModel = new ContactModel();
contactModel.setEmailAddress(email.getAddress());
contactModel.setNikeName(email.getAddress().replace("@gmail.com", ""));
List<AlbumModel> albumModelList = null;
try {
albumModelList = loadAlbum(contactModel.getNikeName());
} catch (Exception e) {
e.printStackTrace();
}
if (albumModelList != null && albumModelList.size() > 0) {
contactModel.setAlbumList(albumModelList);
result.add(contactModel);
}
}
}
}