Container Versions: create

Cần có sự cho phép

Tạo phiên bản vùng chứa. Thử ngay hoặc xem ví dụ.

Yêu cầu

Yêu cầu HTTP

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

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.
containerId string Mã vùng chứa Trình quản lý thẻ của Google (GTM).

Ủy quyền

Yêu cầu này cần được uỷ quyền với 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.edit.containerversions

Nội dung yêu cầu

Trong nội dung yêu cầu, cung cấp dữ liệu có cấu trúc sau:

{
  "quickPreview": boolean,
  "name": string,
  "notes": string
}
Tên tài sản Giá trị Nội dung mô tả Ghi chú
quickPreview boolean Việc tạo phiên bản này có thể chỉ để xem trước nhanh và không nên lưu.
name string Tên của phiên bản vùng chứa sẽ được tạo.
notes string Ghi chú của phiên bản vùng chứa sẽ được tạo.

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:

{
  "containerVersion": accounts.containers.versions Resource,
  "compilerError": boolean
}
Tên tài sản Giá trị Nội dung mô tả Ghi chú
containerVersion nested object Đã tạo phiên bản vùng chứa.
compilerError boolean Trình biên dịch có lỗi hay không.

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 creates a new container version.
 */

// Create the container versions options object.
CreateContainerVersionRequestVersionOptions options =
    new  CreateContainerVersionRequestVersionOptions();
options.setName("Container Version");
options.setNotes("Sample Container Version");
options.setQuickPreview(false);

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


/*
 * The results of the create method are stored in the response object.
 * The following code shows how to access the created id and fingerprint.
 */
System.out.println("Compiler Error = " + response.getCompilerError());
ContainerVersion version = response.getContainerVersion();
if (version != null) {
  System.out.println("Container Version Id = "
      + version.getContainerVersionId());
  System.out.println("Container Version Fingerprint = "
      + version.getFingerprint());
}

Python

Dùng thư viện ứng dụng Python.

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

# This request creates a new container version.
try:
  response = tagmanager.accounts().containers().versions().create(
      accountId='123456',
      containerId='54321',
      body={
          'name': 'Container Version',
          'notes': 'Sample Container Version',
          'quickPreview': True
      }
  ).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 create method are stored in response object.
# The following code shows how to access the created id and fingerprint.
version = response.get('containerVersion', {})
print 'Container Version Id = %s' % version.get('containerVersionId')
print 'Container Version Fingerprint = %s' % version.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.