Search code examples
google-apps-scriptgoogle-contacts-api

Google Contacts Address is not retrieved by my Script (although it is filled)


I try to fetch the content of certain google contacts via Google Apps Script. First I identified the ID of the contact via a getId Function. My Script is this:

 var id = 'id';
 var contact = ContactsApp.getContactById(id);
 var address = contact.getAddresses();
 GmailApp.sendEmail("email", address, "");

The return I get via mail is "AddressField", allthough the certain contact definitely has an address.

In Addition I also tried the following script from the official reference (which returns the same thing):

 // Logs the address for the 'Home Address' field for contact 'John Doe'.
 // Can be used similarly for other fields that contain addresses.
 var contacts = ContactsApp.getContactsByName('John Doe');
 var homeAddress = contacts[0].getAddresses(ContactsApp.Field.HOME_ADDRESS);
 Logger.log(homeAddress[0].getAddress());

Can anyone help me?

Thanks a lot in advance.

Best, Phil


Solution

  • This works for me :

    function testContact(){
      var contacts = ContactsApp.getContactsByName('some name in my contacts');
      Logger.log(contacts[0].getFamilyName());// just to check it's the right one
      var address = contacts[0].getAddresses();
      for (var n=0;n<address.length;n++){
        Logger.log(address[n].getLabel()+' : '+address[n].getAddress());// get all address fields for this contact + corresponding label
      }
    }