Containers: update

需要授权

更新容器。 立即试用查看示例

请求

HTTP 请求

PUT https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers/containerId

参数

参数名称 说明
路径参数
accountId string GTM 帐号 ID。
containerId string GTM 容器 ID。
可选的查询参数
fingerprint string 此指纹(如果提供)必须与所存储的容器的指纹匹配。

授权

此请求需要获得下列范围的授权(详细了解身份验证和授权)。

范围
https://www.googleapis.com/auth/tagmanager.edit.containers

请求正文

在请求正文中,提供具有以下属性的 Containers 资源

属性名称 说明 备注
必需属性
usageContext[] list 容器的使用环境列表。有效值包括:web, android, ios 可写
可选属性
domainName[] list 该容器所关联的可选域名列表。 可写
enabledBuiltInVariable[] list 已启用的内置变量的列表。有效值包括:pageUrl, pageHostname, pagePath, referrer, event, clickElement, clickClasses, clickId, clickTarget, clickUrl, clickText, formElement, formClasses, formId, formTarget, formUrl, formText, errorMessage, errorUrl, errorLine, newHistoryFragment, oldHistoryFragment, newHistoryState, oldHistoryState, historySource, containerVersion, debugMode, randomNumber, containerId 可写
name string 容器的显示名称。 可写
notes string 容器备注。 可写
timeZoneCountryId string 容器国家/地区 ID。 可写
timeZoneId string 容器时区 ID。 可写

响应

如果成功,此方法会在响应正文中返回 Containers 资源

示例

注意:此方法的代码示例并未列出所有受支持的编程语言(请参阅客户端库页面,查看受支持的语言列表)。

Java

使用 Java 客户端库

/*
 * Note: This code assumes you have an authorized tagmanager service object.
 */

/*
 * This request updates an existing container for the authorized user.
 */

// Construct the container object.
Container container = new Container();
container.setName("Example Container");
container.setNotes("Example Container Notes.");
container.setTimeZoneCountryId("US");
container.setTimeZoneId("America/Los_Angeles");
container.setUsageContext(Arrays.asList("web", "android", "ios"));

try {
  Container response = tagmanager.accounts().
      containers().update("123456", "54321", container).execute();
} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}

/*
 * The results of the update method are stored in the response object.
 * The following code shows how to access the updated name and fingerprint.
 */
System.out.println("Updated Name = " + response.getName());
System.out.println("Updated Fingerprint = " + response.getFingerprint());

Python

使用 Python 客户端库

# Note: This code assumes you have an authorized tagmanager service object.

# This request updates an existing container.
try:
  response = tagmanager.accounts().containers().update(
      accountId='123456',
      containerId='54321',
      body={
          'name': 'Example Container',
          'timeZoneCountryId': 'US',
          'timeZoneId': 'America/Los_Angeles',
          'usageContext': ['web', 'android']
      }
  ).execute()

except TypeError, error:
  # Handle errors in constructing a query.
  print 'There was an error in constructing your query : %s' % error

except HttpError, error:
  # Handle API errors.
  print ('There was an API error : %s : %s' %
         (error.resp.status, error.resp.reason))

# The results of the update method are stored in the response object.
# The following code shows how to access the updated name and fingerprint.
print 'Updated Name = %s' % response.get('name')
print 'Updated Fingerprint = %s' % response.get('fingerprint')

试试看!

请使用下面的 API Explorer 对实时数据调用此方法并查看响应。