检索有关Google People API(Java)的联系人的信息

我在这里使用最近发布的Google的People API的示例。 我稍微扩展了一些示例,以显示有关联系人的其他信息,例如电子邮件地址和电话号码。 应该完成这项工作的代码如下所示。

public class PeopleQuickstart { ... public static void getPersonInfo(Person person){ // Get names List names = person.getNames(); if(names != null && names.size() > 0) { for(Name personName: names) { System.out.println("Name: " + personName.getDisplayName()); } } // Get email addresses List emails = person.getEmailAddresses(); if(emails != null && emails.size() > 0) { for(EmailAddress personEmail: emails) { System.out.println("Email: " + personEmail.getValue()); } } // Get phone numbers List 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 connections = response.getConnections(); if (connections != null && connections.size() > 0) { for (Person person: connections){ getPersonInfo(person); } } else { System.out.println("No connections found."); } } } 

我正在使用我的联系人列表测试此程序,我可以成功获取人员列表以及名称字段。 但是,我无法获取电子邮件地址和电话号码的值(列表始终为空),但我确实在联系人列表中设置了这些值(通过Gmail->联系人validation)。 我错过了什么?

好的,问题解决了。 看起来Google的文档有点误导(好吧,它刚刚发布;))。 当我尝试使用people.connections.list (请参阅此处 )获取联系人时,可以设置多个查询参数。 但是,对于requestMask参数,声明“省略此字段将包括所有字段”,但事实并非如此(至少对我不起作用)。 因此,必须明确指定响应中要返回的字段。 修改后的代码如下。 我希望谷歌人能够澄清这一点。

 public class PeopleQuickstart { ... public static void main(String [] args) throws IOException { People service = getPeopleService(); // Request 120 connections. ListConnectionsResponse response = service.people().connections() .list("people/me") .setPageSize(120) // specify fields to be returned .setRequestMaskIncludeField("person.names,person.emailAddresses,person.phoneNumbers") .execute(); // Display information about a person. List connections = response.getConnections(); if (connections != null && connections.size() > 0) { for (Person person: connections){ getPersonInfo(person); } } else { System.out.println("No connections found."); } } }