Class ContactGroup

联系群组

已弃用。请改用 People API 高级服务

ContactGroup 是一组联系人。

方法返回类型简介
addContact(contact)ContactGroup将指定联系人添加到此组
// The code below creates a new contact and adds it to the "Work Friends"
// contact group
const contact = ContactsApp.createContact(
    'John',
    'Doe',
    'john.doe@example.com',
);
const group = ContactsApp.getContactGroup('Work Friends');
group.addContact(contact);
deleteGroup()void删除此联系人群组。
getContacts()Contact[]获取此联系人群组中的所有联系人。
getGroupName()String返回此组的名称。
getId()String获取此联系人群组的 ID。
getName()String获取此联系人群组的名称。
isSystemGroup()Boolean获取一个布尔值,用于确定此联系人群组是否为系统群组(不可删除)。
removeContact(contact)ContactGroup从此组中移除指定联系人
// The code below retrieves all the contacts named "John Doe' and removes them
// from the "Work Friends" contact group
const contacts = ContactsApp.getContactsByName('John Doe');
const group = ContactsApp.getContactGroup('Work Friends');
for (const i in contacts) {
  group.removeContact(contacts[i]);
}
setGroupName(name)void设置此组的名称。
setName(name)ContactGroup设置此联系人群组的名称。

已弃用的方法

已弃用。此函数已废弃,不应在新脚本中使用。

将指定联系人添加到此组

// The code below creates a new contact and adds it to the "Work Friends"
// contact group
const contact = ContactsApp.createContact(
    'John',
    'Doe',
    'john.doe@example.com',
);
const group = ContactsApp.getContactGroup('Work Friends');
group.addContact(contact);

参数

名称类型说明
contactContact要添加到群组的联系人

返回

ContactGroup - 此联系人群组

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

另请参阅


已弃用。此函数已废弃,不应在新脚本中使用。

删除此联系人群组。

仅删除非系统群组;系统群组无法删除。

// The code below retrieves a contact group named "Work Friends" and deletes it
const group = ContactsApp.getContactGroup('Work Friends');
group.deleteGroup();

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

另请参阅


已弃用。此函数已废弃,不应在新脚本中使用。

获取此联系人群组中的所有联系人。

// The code below retrieves all the contacts in the group named "Work Friends"
const group = ContactsApp.getContactGroup('Work Friends');
const contacts = group.getContacts();

返回

Contact[] - 此群组中的联系人

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

已弃用。此函数已废弃,不应在新脚本中使用。

返回此组的名称。

返回

String - 此组的名称

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

已弃用。此函数已废弃,不应在新脚本中使用。

获取此联系人群组的 ID。

// The code below retrieves a contact group named "Work Friends" and gets its id
const group = ContactsApp.getContactGroup('Work Friends');
const id = group.getId();

返回

String - 此组的 ID

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

已弃用。此函数已废弃,不应在新脚本中使用。

获取此联系人群组的名称。

// The code below creates a new contact group and then retrieves its name
const group = ContactsApp.createContactGroup('Work Friends');
const name = group.getName();

返回

String - 此联系人群组的名称

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

另请参阅


已弃用。此函数已废弃,不应在新脚本中使用。

获取一个布尔值,用于确定此联系人群组是否为系统群组(不可删除)。

系统群组是指 Google 通讯录中预定义的一组群组,例如“我的联系人”“家人”“同事”等。系统群组的名称通常包含“系统群组”字样。

// The code below retrieves two contact groups, then logs whether or not
// each is a system group.
const myGroup = ContactsApp.getContactGroup('Work Friends');
const systemGroup = ContactsApp.getContactGroup('System Group: Coworkers');
Logger.log(myGroup.isSystemGroup());      // Returns false, if the group exists.
Logger.log(systemGroup.isSystemGroup());  // Returns true.

返回

Boolean - 此联系人群组是否为系统群组

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

已弃用。此函数已废弃,不应在新脚本中使用。

从此组中移除指定联系人

// The code below retrieves all the contacts named "John Doe' and removes them
// from the "Work Friends" contact group
const contacts = ContactsApp.getContactsByName('John Doe');
const group = ContactsApp.getContactGroup('Work Friends');
for (const i in contacts) {
  group.removeContact(contacts[i]);
}

参数

名称类型说明
contactContact要从群组中移除的联系人

返回

ContactGroup - 此联系人群组

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

另请参阅


已弃用。此函数已废弃,不应在新脚本中使用。

设置此组的名称。

参数

名称类型说明
nameString要为此组设置的名称

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

已弃用。此函数已废弃,不应在新脚本中使用。

设置此联系人群组的名称。

// The code below retrieves the contact group named "Work Friends" and renames
// it to "Work Buddies"
const group = ContactsApp.getContactGroup('Work Friends');
group.setName('Work Buddies');

参数

名称类型说明
nameString联系群组的新名称

返回

ContactGroup - 此联系人群组

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.google.com/m8/feeds

另请参阅