2016-02-24 26 views
5

के साथ संपर्क के बारे में जानकारी प्राप्त करना मैं हाल ही में जारी किए गए Google की पीपुल्स एपीआई का उदाहरण here से उपयोग कर रहा हूं। मैंने एक ईमेल पता और एक फोन नंबर जैसे संपर्क के बारे में अतिरिक्त जानकारी प्रदर्शित करने के लिए एक नमूना बढ़ाया है। कोड जो काम करना चाहिए नीचे प्रस्तुत किया गया है।Google पीपुल्स एपीआई (जावा)

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

मैं अपने संपर्क सूची के साथ इस कार्यक्रम का परीक्षण कर रहा हूँ और मैं सफलतापूर्वक नाम फ़ील्ड के साथ-साथ लोगों की एक सूची प्राप्त कर सकते हैं। हालांकि, मुझे ईमेल पते और फोन नंबरों के लिए मूल्य नहीं मिल सकते हैं (सूचियां हमेशा शून्य होती हैं), हालांकि मेरे पास इन मानों को मेरी संपर्क सूची में सेट किया गया है (जीमेल-> संपर्कों के माध्यम से सत्यापित)। मैं क्या खो रहा हूँ?

उत्तर

16

ठीक है, समस्या हल हो गई। ऐसा लगता है कि Google का दस्तावेज थोड़ा भ्रामक है (ठीक है, इसे अभी जारी किया गया है;))। जब मैं लोगों का उपयोग करके अपने संपर्क लाने की कोशिश करता हूं .connections.list (here देखें) कई क्वेरी पैरामीटर सेट किए जा सकते हैं। हालांकि, अनुरोध के लिए मास्क पैरामीटर यह कहा गया है कि "इस फ़ील्ड को छोड़कर सभी फ़ील्ड शामिल होंगे" जो मामला नहीं है (कम से कम मेरे लिए काम नहीं किया है)। इसलिए, किसी को स्पष्ट रूप से निर्दिष्ट करना होगा कि प्रतिक्रिया में कौन से फ़ील्ड लौटाए जाएंगे। संशोधित कोड नीचे दिया गया है। मेरी इच्छा है कि Google लोग इस बिंदु को थोड़ा सा स्पष्ट करेंगे। , Person.addresses, person.age_range, person.biographies, person.birthdays, person.bragging_rights, person.cover_photos, person.email_addresses, person.events:

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

भावी पीढ़ी के लिए, यहाँ वैध अनुरोध मास्क की सूची है 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.relationship_interests, person.relationship_statuses, person.residences, person.skills, person.taglines, person.urls – GBleaney

+0

वही समस्या थी (http://stackoverflow.com/questions/36466050/why-cant-i-retrieve -emails-पतों और फोन-नंबर-साथ-google-लोगों-api)। खुशी है कि आपको समाधान मिला। हमें इसे Google को रिपोर्ट करनी चाहिए। – nunoarruda

+0

@ फ़ामा धन्यवाद, यह मुझे बचाता है। – Ankur1994a

संबंधित मुद्दे