我需要检索谷歌联系人信息,包括联系人的个人资料图片。为此,我使用下面的代码,除了联系人的个人资料图片外,一切正常:我得到的链接无处可去。有没有其他方法可以获取联系人的头像链接?
GoogleCredential gc = new GoogleCredential();
gc.setAccessToken(accessToken);
ContactsService contactsService = new ContactsService("ServiceName");
contactsService.setOAuth2Credentials(gc);
URL url = new URL("https://www.google.com/m8/feeds/contacts/default/full/?max-results=10000");
ContactFeed feed = null;
try {
feed = contactsService.getFeed(url, ContactFeed.class);
} catch (ServiceException e) {
e.printStackTrace();
}
List<SocialContact> contacts = new ArrayList<>();
if (feed != null) {
for (ContactEntry entry : feed.getEntries()) {
SocialContact contact = new SocialContact();
if (entry.hasName()) {
Name name = entry.getName();
if (name.hasFullName()) {
if (name.hasGivenName()) {
String givenName = name.getGivenName().getValue();
if (name.getGivenName().hasYomi()) {
givenName += " (" + name.getGivenName().getYomi() + ")";
}
contact.setFirstName(givenName);
if (name.hasFamilyName()) {
String familyName = name.getFamilyName().getValue();
if (name.getFamilyName().hasYomi()) {
familyName += " (" + name.getFamilyName().getYomi() + ")";
}
contact.setLastName(familyName);
}
}
}
}
for (PhoneNumber number : entry.getPhoneNumbers()) {
contact.setPhone(number.getPhoneNumber());
}
for (Email email : entry.getEmailAddresses()) {
contact.setEmail(email.getAddress());
}
contact.setProfileImageURL(entry.getContactPhotoLink().getHref());
if(contact.getEmail() != null){
contacts.add(contact);
}
}
}