Class ContactGroup

聯絡Group

已淘汰。請改用 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

另請參閱