0
我需要檢索谷歌聯繫人信息,包括聯繫人的個人資料圖片。爲此,我使用下面的代碼,除了聯繫人的個人資料圖片外,其他所有內容都可以使用:我所獲得的鏈接無處不在。有沒有其他方法可以獲得聯繫人的個人資料圖片鏈接?檢索谷歌聯繫人資料圖片
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);
}
}
}
此解決方案僅返回已添加到聯繫人中的人員。每個寫信給我的聯繫人都不會返回。但照片網址返回正確,我可以看到聯繫人的個人資料圖片 –