【发布时间】:2016-06-06 21:01:18
【问题描述】:
我正在使用here 最近发布的 Google 人员 API 示例。我已经扩展了一个示例以显示有关联系人的其他信息,例如电子邮件地址和电话号码。应该完成这项工作的代码如下所示。
public class PeopleQuickstart {
...
public static void getPersonInfo(Person person){
// Get names
List<Name> names = person.getNames();
if(names != null && names.size() > 0) {
for(Name personName: names) {
System.out.println("Name: " + personName.getDisplayName());
}
}
// Get email addresses
List<EmailAddress> emails = person.getEmailAddresses();
if(emails != null && emails.size() > 0) {
for(EmailAddress personEmail: emails) {
System.out.println("Email: " + personEmail.getValue());
}
}
// Get phone numbers
List<PhoneNumber> phones = person.getPhoneNumbers();
if(phones != null && phones.size() > 0) {
for(PhoneNumber personPhone: phones){
System.out.println("Phone number: " + personPhone.getValue());
}
}
}
public static void main(String [] args) throws IOException {
People service = getPeopleService();
// Request 120 connections.
ListConnectionsResponse response = service.people().connections()
.list("people/me")
.setPageSize(120)
.execute();
// Display information about your connections.
List<Person> connections = response.getConnections();
if (connections != null && connections.size() > 0) {
for (Person person: connections){
getPersonInfo(person);
}
} else {
System.out.println("No connections found.");
}
}
}
我正在使用我的联系人列表测试这个程序,并且我可以成功获取人员列表以及姓名字段。但是,我无法获取电子邮件地址和电话号码的值(列表始终为空),尽管我的联系人列表中确实设置了这些值(通过 Gmail-> 联系人验证)。我错过了什么?
【问题讨论】:
标签: java google-api google-api-client google-contacts-api