注意:此开发者网站正在向 developers.google.com/tag-platform 迁移,2021 年 9 月 30 日起系统会将您重定向到新的网址

Containers:list

需要授权

列出属于 GTM 帐号的所有容器。 立即试用查看示例

请求

HTTP 请求

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

参数

参数名称 说明
路径参数
accountId string GTM 帐号 ID。

授权

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

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

请求正文

请勿使用此方法提供请求正文。

响应

如果成功,此方法将返回采用以下结构的响应正文:

{
  "containers": [
    accounts.containers Resource
  ]
}
属性名称 说明 备注
containers[] list GTM 帐号的所有容器。

示例

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

Java

使用 Java 客户端库

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

/*
 * This request lists all containers for the authorized user.
 */
try {
  ListContainersResponse containers =
      tagmanager.accounts().containers().list("123456").execute();
} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}

/*
 * The results of the list method are stored in the containers object.
 * The following code shows how to iterate through them.
 */
for (Container container : containers.getContainers()) {
  System.out.println("Account Id = " + container.getAccountId());
  System.out.println("Container Id = " + container.getContainerId());
  System.out.println("Container Name = " + container.getName());
  if (container.getDomainName() != null) {
    for (String domain : container.getDomainName()) {
      System.out.println("Domain Name = " + domain);
    }
  }
  System.out.println("Timezone Country Id = "
      + container.getTimeZoneCountryId());
  System.out.println("Timezone Id = " + container.getTimeZoneId());
  System.out.println("Container Notes = " + container.getNotes());
  for (String usageContext : container.getUsageContext()) {
    System.out.println("Usage context = " + usageContext);
  }
  System.out.println("Container Fingerprint = " + container.getFingerprint());
}

Python

使用 Python 客户端库

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

# This request lists all containers for the authorized user.
try:
  containers = tagmanager.accounts().containers().list(
      accountId='123456'
  ).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 list method are stored in the containers object.
# The following code shows how to iterate through them.
for container in containers.get('containers', []):
  print 'Account Id = %s' % container.get('accountId')
  print 'Container Id = %s' % container.get('containerId')
  print 'Container Name = %s' % container.get('name')
  for domain in container.get('domainName', []):
    print 'Domain Name = %s' % domain
  print 'Timezone Country Id = %s' % container.get('timeZoneCountryId')
  print 'Timezone Id = %s' % container.get('timeZone')
  print 'Notes = %s' % container.get('notes')
  for usageContext in container.get('usageContext'):
    print 'Usage Context = %s' % usageContext
  print 'Container Fingerprint = %s\n\n' % container.get('fingerprint')

试用一下!

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