如何在使用 Google Apps 脚本创建联系人时为其添加标签?

How can I add a label to a contact while creating it with Google Apps Script?

我可以在提交表单时创建一个新的 Google 联系人。我需要为这些联系人添加标签,但我找不到任何方法来做到这一点。是否可以添加标签?这是我为 finding/creating 联系人编写的代码片段:

var contact = ContactsApp.getContact(email);
if(!contact){
  contact = ContactsApp.createContact(firstName, lastName, email);
}

要为联系人添加标签,请将联系人添加到联系人组。这是一个示例代码:

  let labelName = 'myLabel';
  let firstName = 'John';
  let lastName = 'Doe';
  let email = 'john.doe@gmail.com';

  //find or create the Contact
  let contact = ContactsApp.getContact(email) || ContactsApp.createContact(firstName, lastName, email);
  }

  //find the Label
  let group = ContactsApp.getContactGroup(labelName);

  //add label to the contact
  group.addContact(contact);