Tôi đang sử dụng ví dụ về API người của Google được phát hành gần đây từ here. Tôi đã mở rộng một mẫu để hiển thị thông tin bổ sung về liên hệ như địa chỉ email và số điện thoại. Mã nên thực hiện công việc được trình bày bên dưới.Truy xuất thông tin về một liên hệ với API của Google People (Java)
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.");
}
}
}
Tôi đang thử nghiệm chương trình này với danh sách liên hệ của mình và tôi có thể có được danh sách người cùng với tên trường thành công. Tuy nhiên, tôi không thể nhận được giá trị cho địa chỉ email và số điện thoại (danh sách luôn rỗng), mặc dù tôi có các giá trị này được đặt trong danh sách liên hệ của mình (được xác minh qua Gmail-> Danh bạ). Tôi đang thiếu gì?
Đối với hậu thế, đây là danh sách các mặt nạ yêu cầu hợp lệ: person.addresses, person.age_range, person.biographies, person.birthdays, person.bragging_rights, person.cover_photos, person.email_addresses, person.events, person.genders, person.im_clients, person.interests, person.locales, person.memberships, person.metadata, person.names, person.nicknames, person.occupations, person.organizations, person.phone_numbers, person.photos, person. mối quan hệ, person.relationship_interests, person.relationship_statuses, person.residences, person.skills, person.taglines, person.urls – GBleaney
Có cùng một vấn đề (http://stackoverflow.com/questions/36466050/why-cant-i-retrieve -emails-addresses-and-phone-numbers-với-google-people-api). Rất vui khi bạn tìm thấy giải pháp. Chúng tôi nên báo cáo điều này cho Google. – nunoarruda
@foma cảm ơn, nó giúp tôi tiết kiệm. – Ankur1994a