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

一个人想着一个人 提交于 2019-12-02 03:26:11

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());
    }
  }
}

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!