Class ContactsApp

聯絡人應用程式

已淘汰。請改用 People API 進階服務

這個類別可讓使用者存取自己的 Google 聯絡人,並建立、移除及更新其中的聯絡人。

屬性類型說明
ExtendedFieldExtendedField
FieldField
GenderGender
MonthMonth
PriorityPriority
SensitivitySensitivity
方法傳回類型簡短說明
createContact(givenName, familyName, email)Contact建立新聯絡人。
createContactGroup(name)ContactGroup建立名稱為指定名稱的聯絡人群組
// The code below creates a new contact group named "Work Friends"
const group = ContactsApp.createContactGroup('Work Friends');
deleteContact(contact)void刪除聯絡人。
deleteContactGroup(group)void刪除聯絡人群組
// The code below creates deletes the contact group named "Work Friends"
const group = ContactsApp.getContactGroup('Work Friends');
ContactsApp.deleteContactGroup(group);
findByEmailAddress(email)Contact尋找使用指定電子郵件地址的聯絡人。
findContactGroup(name)ContactGroup尋找指定名稱的聯絡人群組。
getAllContacts()Contact[]取得屬於此使用者的所有聯絡人。
getContact(emailAddress)Contact根據電子郵件地址取得聯絡人。
getContactById(id)Contact取得使用此 ID 的聯絡人。
getContactGroup(name)ContactGroup取得具有指定名稱的聯絡人群組,如果找不到這樣的聯絡人群組,則會傳回空值。
getContactGroupById(id)ContactGroup取得指定 ID 的聯絡人群組,如果找不到這類群組,則傳回 null。
getContactGroups()ContactGroup[]取得使用者的完整聯絡人群組清單。
getContacts()Contact[]取得使用者的所有聯絡人。
getContactsByAddress(query)Contact[]取得符合地址的聯絡人。
getContactsByAddress(query, label)Contact[]取得符合特定欄位地址的聯絡人。
getContactsByAddress(query, label)Contact[]取得符合地址的聯絡人,但僅限於指定的自訂地址標籤。
getContactsByCompany(query)Contact[]取得符合公司欄位條件的聯絡人。
getContactsByCustomField(query, label)Contact[]取得符合自訂欄位中指定值的聯絡人。
getContactsByDate(month, day, label)Contact[]取得符合特定標準欄位中指定月份和日期的聯絡人。
getContactsByDate(month, day, year, label)Contact[]取得符合特定標準欄位中指定月份、日期和年份的聯絡人。
getContactsByDate(month, day, year, label)Contact[]取得符合特定自訂欄位指定月份、日期和年份的聯絡人。
getContactsByDate(month, day, label)Contact[]取得符合特定自訂欄位指定月份和日期的聯絡人。
getContactsByEmailAddress(query)Contact[]取得符合電子郵件地址的聯絡人。
getContactsByEmailAddress(query, label)Contact[]取得符合電子郵件地址的聯絡人,但僅限於特定欄位。
getContactsByEmailAddress(query, label)Contact[]取得符合電子郵件地址的聯絡人,但僅限於指定的自訂電子郵件地址標籤。
getContactsByGroup(group)Contact[]取得指定 ContactGroup 中的聯絡人。
getContactsByIM(query)Contact[]取得符合某個即時通訊地址的聯絡人。
getContactsByIM(query, label)Contact[]取得符合某個特定欄位的即時通訊地址的聯絡人。
getContactsByIM(query, label)Contact[]取得符合即時通訊地址的聯絡人,但僅限於指定的自訂即時通訊標籤。
getContactsByJobTitle(query)Contact[]取得符合職稱欄位條件的聯絡人。
getContactsByName(query)Contact[]取得符合名稱的聯絡人。
getContactsByName(query, label)Contact[]取得符合特定欄位名稱的聯絡人。
getContactsByNotes(query)Contact[]取得符合「notes」欄位的聯絡人。
getContactsByPhone(query)Contact[]取得符合電話號碼的聯絡人。
getContactsByPhone(query, label)Contact[]取得符合電話號碼的聯絡人,但僅限於特定欄位。
getContactsByPhone(query, label)Contact[]取得符合電話號碼的聯絡人,但僅限於指定的自訂電話號碼標籤。
getContactsByUrl(query)Contact[]取得符合網址的聯絡人。
getContactsByUrl(query, label)Contact[]取得符合特定網址的聯絡人,但僅限於特定欄位。
getContactsByUrl(query, label)Contact[]取得符合網址的聯絡人,僅限於指定的自訂網址標籤。

已淘汰的方法

已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

建立新聯絡人。

// The code below creates a new contact with the name "John Doe" and the email
// address "john.doe@example.com".
const contact = ContactsApp.createContact(
    'John',
    'Doe',
    'john.doe@example.com',
);

參數

名稱類型說明
givenNameString聯絡人的名字
familyNameString聯絡人的姓氏
emailString聯絡人的電子郵件地址

回攻員

Contact:新建立的 Contact 物件

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

建立名稱為指定名稱的聯絡人群組

// The code below creates a new contact group named "Work Friends"
const group = ContactsApp.createContactGroup('Work Friends');

參數

名稱類型說明
nameString新聯絡人群組的名稱

回攻員

ContactGroup:新建立的聯絡人群組

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

刪除聯絡人。

// The code below retrieves a contact with the email address
// "john.doe@example.com" and then deletes that contact.
const contact = ContactsApp.getContact('john.doe@example.com');
ContactsApp.deleteContact(contact);

參數

名稱類型說明
contactContact要刪除的聯絡人

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

刪除聯絡人群組

// The code below creates deletes the contact group named "Work Friends"
const group = ContactsApp.getContactGroup('Work Friends');
ContactsApp.deleteContactGroup(group);

參數

名稱類型說明
groupContactGroup要刪除的聯絡人群組

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

尋找使用指定電子郵件地址的聯絡人。

參數

名稱類型說明
emailString要查詢的聯絡人電子郵件地址

回攻員

Contact:含有該電子郵件地址的聯絡人

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

尋找指定名稱的聯絡人群組。

參數

名稱類型說明
nameString要尋找的聯絡人群組名稱

回攻員

ContactGroup:與指定名稱相符的聯絡人群組

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得屬於此使用者的所有聯絡人。

回攻員

Contact[]:這個使用者的所有聯絡人

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

根據電子郵件地址取得聯絡人。

如果有多位聯絡人使用相同的電子郵件地址,這個方法會優先選擇將電子郵件地址標示為主要聯絡人的聯絡人;如果沒有任何聯絡人將電子郵件地址標示為主要聯絡人,或是有多位聯絡人將電子郵件地址標示為主要聯絡人,則會依照排序的聯絡人順序傳回第一個結果。

// The code below retrieves a contact with the email address
// "john.doe@example.com".
const contact = ContactsApp.getContact('john.doe@example.com');

參數

名稱類型說明
emailAddressString聯絡人的電子郵件地址

回攻員

Contact:含有該電子郵件地址的聯絡人

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得使用此 ID 的聯絡人。

// The code below retrieves the contact with the id
// "http://www.google.com/m8/feeds/contacts/john.doe%40example.com/base/7c86afde08d34ca5"
const id =
    'http://www.google.com/m8/feeds/contacts/john.doe%40example.com/base/7c86afde08d34c';
const contact = ContactsApp.getContactById(id);

參數

名稱類型說明
idString要擷取的聯絡人 ID

回攻員

Contact:相符的聯絡人或空值

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得具有指定名稱的聯絡人群組,如果找不到這樣的聯絡人群組,則傳回空值。

// The code below returns the contact group with the name "Work Friends"
const group = ContactsApp.getContactGroup('Work Friends');

參數

名稱類型說明
nameString要比對的聯絡人群組名稱

回攻員

ContactGroup:相符的聯絡人群組,如果找不到相符的聯絡人群組,則為空值

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得指定 ID 的聯絡人群組,如果找不到這類聯絡人群組,則傳回 null。

// The code below returns the contact group with the id
// "http://www.google.com/m8/feeds/groups/john.doe%40example.com/base/54eefbb093fdecb"
const id =
    'http://www.google.com/m8/feeds/groups/john.doe%40example.com/base/54eefbb093fdecb';
const group = ContactsApp.getContactGroupById(id);

參數

名稱類型說明
idString要比對的聯絡人群組 ID

回攻員

ContactGroup:相符的聯絡人群組,如果找不到相符的聯絡人群組,則為空值

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得使用者的完整聯絡人群組清單。

使用者可以擁有聯絡人清單,也可能擁有聯絡人群組清單。每個聯絡人群組都可以包含聯絡人。這個方法會傳回所有聯絡人群組的清單。

// The retrieves all the contract groups for the user and then logs the group
// name of each contact group.
const groups = ContactsApp.getContactGroups();
for (let i = 0; i < groups.length; i++) {
  Logger.log(groups[i].getName());
}

回攻員

ContactGroup[]:使用者聯絡人群組的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得使用者的所有聯絡人。

// The code below will retrieve all the user's contacts
const contacts = ContactsApp.getContacts();

回攻員

Contact[]:所有使用者聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合地址的聯絡人。

// The code below returns an array of contacts where the contact's address
// contains "San Francisco'.
const contacts = ContactsApp.getContactsByAddress('San Francisco');

參數

名稱類型說明
queryString在聯絡地址中搜尋的字串

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合特定地址的聯絡人,但僅限於特定欄位。

// The code below returns an array of contacts where the contact's address
// contains "San Francisco" in the Home address field.
const contacts = ContactsApp.getContactsByAddress(
    'San Francisco',
    ContactsApp.Field.HOME_ADDRESS,
);

參數

名稱類型說明
queryString在聯絡地址中搜尋的字串
labelField要搜尋的欄位

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合地址的聯絡人,但僅限於指定的自訂地址標籤。

// The code below returns an array of contacts where the contact's address
// contains "San Francisco" in a custom address label (created by the user)
// called "vacation".
const contacts = ContactsApp.getContactsByAddress('San Francisco', 'vacation');

參數

名稱類型說明
queryString在聯絡人地址中搜尋的字串,其中包含指定的自訂地址標籤
labelString要搜尋的自訂地址標籤

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合公司欄位條件的聯絡人。

// The code below returns an array of contacts where the contact's company field
// contains "Google".
const contacts = ContactsApp.getContactsByCompany('Google');

參數

名稱類型說明
queryString要在聯絡人的公司名稱欄位中搜尋的字串

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合自訂欄位中指定值的聯絡人。

您可以使用字串或 ContactsApp.ExtendedField 值之一來指定自訂欄位。

// The code below returns an array of contacts where the contact's custom field
// named "Favorite Sport" contains "tennis".
const contacts = ContactsApp.getContactsByCustomField(
    'tennis',
    'Favorite Sport',
);

參數

名稱類型說明
queryObject在聯絡人的自訂欄位中搜尋的字串
labelExtendedField要搜尋的自訂欄位

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合特定標準欄位指定月份和日期的聯絡人。

// The code below returns an array of contacts where the contact's "Birthday"
// field contains April for the month and 19 for the day.
const contacts = ContactsApp.getContactsByDate(
    ContactsApp.Month.APRIL,
    19,
    ContactsApp.Field.BIRTHDAY,
);

參數

名稱類型說明
monthMonth要比對的月份,為 ContactsApp.Month 的其中一個值
dayInteger要比對的日期
labelField要搜尋的欄位,來自 ContactsApp.Field

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合特定標準欄位中指定月份、日期和年份的聯絡人。

// The code below returns an array of contacts where the contact's "Birthday"
// field contains April for the month, 19 for the day, and 1950 for the year.
const contacts = ContactsApp.getContactsByDate(
    ContactsApp.Month.APRIL,
    19,
    1950,
    ContactsApp.Field.BIRTHDAY,
);

參數

名稱類型說明
monthMonth要比對的月份,為 ContactsApp.Month 的其中一個值
dayInteger要比對的日期
yearInteger要比對的年份,可為空值
labelField要搜尋的欄位,來自 ContactsApp.Field

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合特定自訂欄位中指定月份、日期和年份的聯絡人。

// The code below returns an array of contacts where the contact's custom "Start
// Date" field contains April for the month, 19 for the day, and 2011 for the
// year.
const contacts = ContactsApp.getContactsByDate(
    ContactsApp.Month.APRIL,
    19,
    2011,
    'Start Date',
);

參數

名稱類型說明
monthMonth要比對的月份,為 ContactsApp.Month 的其中一個值
dayInteger要比對的日期
yearInteger要比對的年份,可為空值
labelString要搜尋的自訂欄位

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合特定自訂欄位指定月份和日期的聯絡人。

// The code below returns an array of contacts where the contact's custom "Start
// Date" field contains April for the month and 19 for the day.
const contacts = ContactsApp.getContactsByDate(
    ContactsApp.Month.APRIL,
    19,
    'Start Date',
);

參數

名稱類型說明
monthMonth要比對的月份,為 ContactsApp.Month 的其中一個值
dayInteger要比對的日期
labelString要搜尋的自訂欄位

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合電子郵件地址的聯絡人。

// The code below returns an array of contacts where the contact's email address
// contains "john.doe@example.com'.
const contacts = ContactsApp.getContactsByEmailAddress('john.doe@example.com');

參數

名稱類型說明
queryString在聯絡人電子郵件地址中搜尋的字串

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合電子郵件地址的聯絡人,但僅限於特定欄位。

// The code below returns an array of contacts where the contact's email address
// contains "john.doe@example.com" in the Home email field.
const contacts = ContactsApp.getContactsByEmailAddress(
    'john.doe@example.com',
    ContactsApp.Field.HOME_EMAIL,
);

參數

名稱類型說明
queryString在聯絡人電子郵件地址中搜尋的字串
labelField要搜尋的欄位

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合電子郵件地址的聯絡人,但僅限於指定的自訂電子郵件地址標籤。

// The code below returns an array of contacts where the contact's email address
// contains "john.doe@example.com" in a custom email address label (created by
// the user) called "alternate".
const contacts = ContactsApp.getContactsByEmailAddress(
    'john.doe@example.com',
    'alternate',
);

參數

名稱類型說明
queryString在聯絡人電子郵件地址中搜尋的字串,以及指定的自訂電子郵件地址標籤
labelString自訂電子郵件地址標籤,用於搜尋

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得指定 ContactGroup 中的聯絡人。

// The code below returns an array of contacts in the ContactGroup with the name
// "Work Friends".
const group = ContactsApp.getContactGroup('Work Friends');
const contacts = ContactsApp.getContactsByGroup(group);

參數

名稱類型說明
groupContactGroup聯絡人群組

回攻員

Contact[]:指定群組中的聯絡人陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合某個即時通訊地址的聯絡人。

// The code below returns an array of contacts where the contact's instant
// messaging address contains "ChatWithJohnDoe" in any instant messaging field.
const contacts = ContactsApp.getContactsByIM('ChatWithJohnDoe');

參數

名稱類型說明
queryString在聯絡人的即時通訊地址中搜尋的字串

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合某個特定欄位的即時通訊地址的聯絡人。

// The code below returns an array of contacts where the contact's instant
// messaging address contains "ChatWithJohnDoe" in the AIM instant messaging
// field.
const contacts = ContactsApp.getContactsByIM(
    'ChatWithJohnDoe',
    ContactsApp.Field.AIM,
);

參數

名稱類型說明
queryString在聯絡人的即時通訊地址中搜尋的字串
labelField要搜尋的欄位

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合即時通訊地址的聯絡人,但僅限於指定的自訂即時通訊標籤。

// The code below returns an array of contacts where the contact's instant
// messaging address contains "ChatWithJohnDoe" in a custom instant messaging
// label (created by the user) called "eBuddy".
const contacts = ContactsApp.getContactsByIM('ChatWithJohnDoe', 'eBuddy');

參數

名稱類型說明
queryString在聯絡人的即時通訊地址中搜尋的字串,其中包含指定的自訂即時通訊標籤
labelString要搜尋的自訂即時通訊標籤

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合職稱欄位條件的聯絡人。

// The code below returns an array of contacts where the contact's job title
// field contains "Product Manager".
const contacts = ContactsApp.getContactsByJobTitle('Product Manager');

參數

名稱類型說明
queryString在聯絡人的職稱欄位中搜尋的字串

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合名稱的聯絡人。

// The code below returns an array of contacts where the contact name contains
// "John"
const contacts = ContactsApp.getContactsByName('John');

參數

名稱類型說明
queryString在聯絡人姓名中搜尋的字串

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合名稱的聯絡人,但僅限於特定欄位。

// The code below returns an array of contacts where the contact name contains
// "John" in the Given Name field.
const contacts = ContactsApp.getContactsByName(
    'John',
    ContactsApp.Field.GIVEN_NAME,
);

參數

名稱類型說明
queryString在聯絡人姓名中搜尋的字串
labelField要搜尋的欄位

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合「notes」欄位的聯絡人。

// The code below returns an array of contacts where the contact's notes field
// contains "sent birthday card".
const contacts = ContactsApp.getContactsByNotes('sent birthday card');

參數

名稱類型說明
queryString在聯絡人的備註欄位中搜尋的字串

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合電話號碼的聯絡人。

這個方法會展開含字母的電話號碼,因此如果您搜尋「212-555-CODE」,而聯絡人中含有「212-555-2633」或相反的情況,這個方法就會找到適當的聯絡人。

// The code below returns an array of contacts where the contact's phone number
// contains "212-555-1234' in any phone number field.
const contacts = ContactsApp.getContactsByPhone('212-555-1234');

參數

名稱類型說明
queryString在聯絡人的電話號碼中搜尋的字串

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合電話號碼的聯絡人,但僅限於特定欄位。

這個方法會展開含字母的電話號碼,因此如果您搜尋「212-555-CODE」,而聯絡人中含有「212-555-2633」或相反的情況,這個方法就會找到適當的聯絡人。

// The code below returns an array of contacts where the contact's phone number
// contains "212-555-1234" in the Home phone number field.
const contacts = ContactsApp.getContactsByPhone(
    '212-555-1234',
    ContactsApp.Field.HOME_PHONE,
);

參數

名稱類型說明
queryString在聯絡人的電話號碼中搜尋的字串
labelField要搜尋的欄位

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合電話號碼的聯絡人,但僅限於指定的自訂電話號碼標籤。

這個方法會展開含字母的電話號碼,因此如果您搜尋「212-555-CODE」,而聯絡人中含有「212-555-2633」或相反的情況,這個方法就會找到適當的聯絡人。

// The code below returns an array of contacts where the contact's phone number
// contains "212-555-1234" in a custom phone number label (created by the user)
// called "alternate".
const contacts = ContactsApp.getContactsByPhone('212-555-1234', 'alternate');

參數

名稱類型說明
queryString在聯絡人的電話號碼中搜尋指定自訂電話號碼標籤的字串
labelString要搜尋的自訂電話號碼標籤

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合網址的聯絡人。

// The code below returns an array of contacts where the contact's URL contains
// "www.example.com' in any URL field.
const contacts = ContactsApp.getContactsByUrl('www.example.com');

參數

名稱類型說明
queryString要在聯絡人網址中搜尋的字串

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合特定網址的聯絡人,僅限於特定欄位。

// The code below returns an array of contacts where the contact's URL contains
// "www.example.com" in the Work URL field.
const contacts = ContactsApp.getContactsByUrl(
    'www.example.com',
    ContactsApp.Field.WORK_WEBSITE,
);

參數

名稱類型說明
queryString要在聯絡人網址中搜尋的字串
labelField要搜尋的欄位

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱


已淘汰。這個函式已淘汰,不建議在新指令碼中使用。

取得符合網址的聯絡人,僅限於指定的自訂網址標籤。

// The code below returns an array of contacts where the contact's URL contains
// "www.example.com" in a custom URL label (created by the user) called
// "alternate work".
const contacts = ContactsApp.getContactsByUrl(
    'www.example.com',
    'alternate work',
);

參數

名稱類型說明
queryString在聯絡人網址中搜尋的字串,並使用指定的自訂網址標籤
labelString要搜尋的自訂網址標籤

回攻員

Contact[]:相符聯絡人的陣列

授權

使用這個方法的腳本需要具備下列一或多個範圍的授權:

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

另請參閱