2016-02-24 18 views
5

here'dan Google'ın People API'sine bir örnek vereceğim. Bir e-posta adresi ve telefon numarası gibi kişi hakkında ek bilgi görüntülemek için bir örnek uzattım. İşi yapması gereken kod aşağıda sunulmuştur.Google Kişiler API'sı (Java) ile bir kişi hakkında bilgi alma

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."); 
     } 
    } 
} 

Kişi listeme ile bu programı test ediyorum ve ben başarılı isim alanları ile birlikte kullanıcıların bir listesini elde edebilirsiniz. Ancak, e-posta adresleri ve telefon numaraları için değerler alamıyorum (listeler her zaman boştur), ancak bu değerleri kişi listemde (Gmail -> Kişiler aracılığıyla doğrulanmış) ayarladım. Neyi kaçırıyorum?

cevap

16

Tamam, sorun çözüldü. Google'ın dokümantasyonunun biraz yanıltıcı olduğu anlaşılıyor (iyi, yeni piyasaya sürüldü;)). Kişilerimi people.connections.list (bkz. here) kullanarak getirmeye çalıştığımda, ayarlanabilen birkaç sorgu parametresi vardır. Ancak, requestMask parametresi için, "Bu alanın çıkarılması tüm alanları içerecektir" (ki en azından benim için işe yaramadı). Bu nedenle, biri yanıtta hangi alanların döndürüleceğini açıkça belirtmelidir. Değiştirilen kod aşağıda verilmiştir. Google'ın bu noktayı biraz açıklığa kavuşturmasını dilerim. , Person.addresses, person.age_range, person.biographies, person.birthdays, person.bragging_rights, person.cover_photos, person.email_addresses, person.events:

kuşaklar için
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<Person> connections = response.getConnections(); 
     if (connections != null && connections.size() > 0) { 
      for (Person person: connections){ 
       getPersonInfo(person); 
      } 
     } else { 
      System.out.println("No connections found."); 
     } 
    } 
} 
+5

, burada Geçerli bir istek maskelerinin listesi 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, kişi. İlişkiler, person.relationship_interests, person.relationship_statuses, person.residences, person.skills, person.taglines, person.urls – GBleaney

+0

Aynı sorun vardı (http://stackoverflow.com/questions/36466050/why-cant-i-retrieve -emails-adresler-ve-telefon-numaraları-ile-google-insan-api). Çözümü bulduğuna sevindim. Bunu Google’a bildirmeliyiz. – nunoarruda

+0

@foma teşekkürler, beni kurtarıyor. – Ankur1994a

İlgili konular