3
votes

I am trying to get contact name, email and phone from google contact api from contact feed http://www.google.com/m8/feeds/contacts/default/full

var entries = result.feed.entry;

for (var i = 0; i < entries.length; i++) {
    var contactEntry = entries[i];
    var emailAddresses = contactEntry.getEmailAddresses();

    for (var j = 0; j < emailAddresses.length; j++) {
        var emailAddress = emailAddresses[j].getAddress();
        vemail += emailAddress + ',';
    }

     var fname = contactEntry.getPhoneNumbers();

    if (phoneNumbers.length == 0) {
        console.log('phone number = N/A');
    } else {         
        for (var j = 0; j < phoneNumbers.length; j++) {
            var phoneNumber = phoneNumbers[j].getValue() || 'N/A';
            console.log('phone number = ' + phoneNumber);
        }
    }
}

I can get phone number and email from the code above. May I know how to get the name too? Thanks

1

1 Answers

6
votes

Contact name is stored in contactEntry.title.$t, you can get it using contactEntry.getTitle().getText();

Reference: http://www.mycodeland.com/?p=25

P.S. you can also try console.log(contactEntry) in chrome. This will output the whole contact object for you in console so you can browse through it's properties and methods.