Add contacts to Google Contacts' main Contacts list (not hidden)

前端 未结 2 1097
春和景丽
春和景丽 2020-12-22 00:34

I\'m using the GAS code bellow to add a new contact into Google Contacts (https://contacts.google.com/):

var contact = ContactsApp.createContact(\'Bbbb\', \'C         


        
相关标签:
2条回答
  • 2020-12-22 01:17

    For me, I have to add them to the ContactGroup named System Group: My Contacts.

    function finishAddingContact(contact) {
      var mainGroup = ContactsApp.getContactGroup("System Group: My Contacts");
      if(mainGroup)
        mainGroup.addContact(contact);
    }
    

    Note that getContactGroup(string) is an exact name match.

    I recommend inspecting your ContactGroups for system groups, and then selecting the appropriate one from that list. It's probably the one with the most contacts in it:

    function inspect() {
      var groups = ContactsApp.getContactGroups();
      for(var g = 0; g < groups.length; ++g) {
        if(groups[g].isSystemGroup()) {
          Logger.log(groups[g].getName() + ": " + groups[g].getContacts().length + " members, id=" + groups[g].getId());
        }
      }
    }
    
    0 讨论(0)
  • 2020-12-22 01:21

    Thanks a lot tehhwch.

    I used your second code to get the right group ("System Group: My Contacts"), and then:

    var contact = ContactsApp.createContact('Wunder', 'Bar', 'excellent@help.com');
    var group = ContactsApp.getContactGroup("System Group: My Contacts");
    group.addContact(contact);
    

    It works, and the contact is immediately visible in my Android device.

    0 讨论(0)
提交回复
热议问题