Containers: list

Cần có sự cho phép

Liệt kê tất cả các vùng chứa thuộc tài khoản GTM. Thử ngay hoặc xem ví dụ.

Yêu cầu

Yêu cầu HTTP

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

Các tham số

Tên thông số Giá trị Nội dung mô tả
Tham số đường dẫn
accountId string Mã tài khoản GTM.

Ủy quyền

Yêu cầu này cần được uỷ quyền với ít nhất một trong các phạm vi sau (đọc thêm về quy trình xác thực và uỷ quyền).

Phạm vi
https://www.googleapis.com/auth/tagmanager.readonly
https://www.googleapis.com/auth/tagmanager.edit.containers

Nội dung yêu cầu

Đừng cung cấp nội dung yêu cầu bằng phương thức này.

Phản hồi

Nếu thành công, phương thức này sẽ trả về một nội dung phản hồi có cấu trúc như sau:

{
  "containers": [
    accounts.containers Resource
  ]
}
Tên tài sản Giá trị Nội dung mô tả Ghi chú
containers[] list Tất cả các vùng chứa của tài khoản GTM.

Ví dụ

Lưu ý: Các đoạn mã mẫu của phương thức này không phải là ví dụ cho mọi ngôn ngữ lập trình được hỗ trợ (xem trang thông tin về các thư viện dùng cho ứng dụng để biết danh sách các ngôn ngữ được hỗ trợ).

Java

Sử dụng thư viện ứng dụng 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

Dùng thư viện ứng dụng 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')

Hãy dùng thử!

Hãy sử dụng APIs Explorer bên dưới để gọi phương thức này trên dữ liệu trực tiếp và xem phản hồi.