Class UrlField
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
详细文档
getAddress()
获取此字段的地址。
// Logs the address for the 'Home Address' field for contact 'John Doe'.
// Can be used similarly for other fields that contain addresses.
const contacts = ContactsApp.getContactsByName('John Doe');
const homeAddress = contacts[0].getAddresses(ContactsApp.Field.HOME_ADDRESS);
Logger.log(homeAddress[0].getAddress());
返回
String
- 地址(字符串)
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
getLabel()
获取此字段的标签。这可以是 Field、ExtendedField 或 String。
// Logs the label for all the address fields associated with contact
// 'John Doe'. This method can be similarly called for any field that has
// a label.
const contacts = ContactsApp.getContactsByName('John Doe');
const addressFields = contacts[0].getAddresses();
for (let i = 0; i < addressFields.length; i++) {
Logger.log(addressFields[i].getLabel());
}
返回
Object
- 此字段的标签
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
isPrimary()
获取这是主字段值的标志。
// Logs whether or not the first address field associated with contact
// 'John Doe' is labeled as primary. This method can be similarly called
// for any field.
const contacts = ContactsApp.getContactsByName('John Doe');
const addressFields = contacts[0].getAddresses();
Logger.log(addressFields[0].isPrimary());
返回
Boolean
- 是否为主
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
setAddress(address)
设置此字段的地址。
// Sets the address for the 'Home Address' field for contact 'John Doe'.
// Can be used similarly for other fields that contain addresses.
const contacts = ContactsApp.getContactsByName('John Doe');
const homeAddress = contacts[0].getAddresses(ContactsApp.Field.HOME_ADDRESS);
homeAddress[0].setAddress('123 Main St, Raleigh, NC, 27601');
参数
返回
UrlField
- this 字段,适用于链式调用
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
setAsPrimary()
将此字段设置为主要字段。
// Sets the first address field associated with contact 'John Doe'
// as primary. This method can be similarly called for any field.
const contacts = ContactsApp.getContactsByName('John Doe');
const addressFields = contacts[0].getAddresses();
addressFields[0].setAsPrimary();
返回
UrlField
- 用于链式调用的 this FieldValue
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
setLabel(field)
设置此字段的标签。
// Sets the label to 'Work' for the first address field associated
// with contact 'John Doe'. This method can be similarly called for any
// field that has a label.
const contacts = ContactsApp.getContactsByName('John Doe');
const addressFields = contacts[0].getAddresses();
addressFields[0].setLabel(ContactsApp.Field.WORK_ADDRESS);
参数
返回
UrlField
- 用于链式调用的 this FieldValue
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
setLabel(label)
设置此字段的标签。
// Sets the label to 'Apartment' for the first address field associated
// with contact 'John Doe'. This method can be similarly called for any
// field that has a label.
const contacts = ContactsApp.getContactsByName('John Doe');
const addressFields = contacts[0].getAddresses();
addressFields[0].setLabel('Apartment');
参数
名称 | 类型 | 说明 |
label | String | 此字段的新标签 |
返回
UrlField
- this 字段,适用于链式调用
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
已弃用的方法
deleteUrlField()
已弃用。此函数已废弃,不应在新脚本中使用。
删除此网址字段。
// Retrieves and deletes the Blog URL field for contact 'John
// Doe'
const contacts = ContactsApp.getContactsByName('John Doe');
const urlFields = contacts[0].getUrls(ContactsApp.Field.BLOG);
urlFields[0].deleteUrlField();
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.google.com/m8/feeds
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003e\u003ccode\u003eUrlField\u003c/code\u003e is deprecated and the People API advanced service should be used instead.\u003c/p\u003e\n"],["\u003cp\u003eIt represents a URL field within a Contact and allows you to get or set the address, label, and primary status.\u003c/p\u003e\n"],["\u003cp\u003eProvides methods to programmatically interact with a contact's URL field, such as setting the address, label, or designating it as primary.\u003c/p\u003e\n"],["\u003cp\u003eIncludes a deprecated \u003ccode\u003edeleteUrlField()\u003c/code\u003e method, which should be avoided in new scripts.\u003c/p\u003e\n"]]],[],null,["# Class UrlField\n\nUrlField\n\n\n**Deprecated.** Instead, use the [People API advanced\nservice](/apps-script/advanced/people)\n\nA URL field in a Contact. \n\n### Methods\n\n| Method | Return type | Brief description |\n|--------------------------------------------|---------------|-----------------------------------------------|\n| [getAddress()](#getAddress()) | `String` | Get the address for this field. |\n| [getLabel()](#getLabel()) | `Object` | Gets the label for this field. |\n| [isPrimary()](#isPrimary()) | `Boolean` | Gets whether this is the primary field value. |\n| [setAddress(address)](#setAddress(String)) | [UrlField](#) | Sets the address of this field. |\n| [setAsPrimary()](#setAsPrimary()) | [UrlField](#) | Sets this field to primary. |\n| [setLabel(field)](#setLabel(Field)) | [UrlField](#) | Sets the label of this field. |\n| [setLabel(label)](#setLabel(String)) | [UrlField](#) | Sets the label of this field. |\n\n### Deprecated methods\n\n| Method | Return type | Brief description |\n|---------------------------------------|-------------|-------------------------|\n| [deleteUrlField()](#deleteUrlField()) | `void` | Deletes this URL field. |\n\nDetailed documentation\n----------------------\n\n### `get``Address()`\n\nGet the address for this field.\n\n```javascript\n// Logs the address for the 'Home Address' field for contact 'John Doe'.\n// Can be used similarly for other fields that contain addresses.\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst homeAddress = contacts[0].getAddresses(ContactsApp.Field.HOME_ADDRESS);\nLogger.log(homeAddress[0].getAddress());\n```\n\n#### Return\n\n\n`String` --- the address as a string\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n### `get``Label()`\n\nGets the label for this field. This may be a Field, ExtendedField, or a String.\n\n```javascript\n// Logs the label for all the address fields associated with contact\n// 'John Doe'. This method can be similarly called for any field that has\n// a label.\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst addressFields = contacts[0].getAddresses();\nfor (let i = 0; i \u003c addressFields.length; i++) {\n Logger.log(addressFields[i].getLabel());\n}\n```\n\n#### Return\n\n\n`Object` --- the label for this field\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n### `is``Primary()`\n\nGets whether this is the primary field value.\n\n```javascript\n// Logs whether or not the first address field associated with contact\n// 'John Doe' is labeled as primary. This method can be similarly called\n// for any field.\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst addressFields = contacts[0].getAddresses();\nLogger.log(addressFields[0].isPrimary());\n```\n\n#### Return\n\n\n`Boolean` --- whether this is primary\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n### `set``Address(address)`\n\nSets the address of this field.\n\n```javascript\n// Sets the address for the 'Home Address' field for contact 'John Doe'.\n// Can be used similarly for other fields that contain addresses.\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst homeAddress = contacts[0].getAddresses(ContactsApp.Field.HOME_ADDRESS);\nhomeAddress[0].setAddress('123 Main St, Raleigh, NC, 27601');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-----------|----------|-----------------|\n| `address` | `String` | the new address |\n\n#### Return\n\n\n[UrlField](#) --- this field, useful for chaining\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n### `set``As``Primary()`\n\nSets this field to primary.\n\n```javascript\n// Sets the first address field associated with contact 'John Doe'\n// as primary. This method can be similarly called for any field.\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst addressFields = contacts[0].getAddresses();\naddressFields[0].setAsPrimary();\n```\n\n#### Return\n\n\n[UrlField](#) --- this FieldValue for chaining\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n### `set``Label(field)`\n\nSets the label of this field.\n\n```javascript\n// Sets the label to 'Work' for the first address field associated\n// with contact 'John Doe'. This method can be similarly called for any\n// field that has a label.\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst addressFields = contacts[0].getAddresses();\naddressFields[0].setLabel(ContactsApp.Field.WORK_ADDRESS);\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|---------|------------------------------------------------|------------------------|\n| `field` | [Field](/apps-script/reference/contacts/field) | the new standard label |\n\n#### Return\n\n\n[UrlField](#) --- this FieldValue for chaining\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\n*** ** * ** ***\n\n### `set``Label(label)`\n\nSets the label of this field.\n\n```javascript\n// Sets the label to 'Apartment' for the first address field associated\n// with contact 'John Doe'. This method can be similarly called for any\n// field that has a label.\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst addressFields = contacts[0].getAddresses();\naddressFields[0].setLabel('Apartment');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|---------|----------|------------------------------|\n| `label` | `String` | the new label for this field |\n\n#### Return\n\n\n[UrlField](#) --- this field, useful for chaining\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`\n\nDeprecated methods\n------------------\n\n### `delete``Url``Field()`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nDeletes this URL field.\n\n```javascript\n// Retrieves and deletes the Blog URL field for contact 'John\n// Doe'\nconst contacts = ContactsApp.getContactsByName('John Doe');\nconst urlFields = contacts[0].getUrls(ContactsApp.Field.BLOG);\nurlFields[0].deleteUrlField();\n```\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.google.com/m8/feeds`"]]