需要授权
请求
HTTP 请求
POST https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers/containerId/versions
参数
参数名称 | 值 | 说明 |
---|---|---|
路径参数 | ||
accountId |
string |
GTM 帐号 ID。 |
containerId |
string |
GTM 容器 ID。 |
授权
此请求需要获得下列范围的授权(详细了解身份验证和授权)。
范围 |
---|
https://www.googleapis.com/auth/tagmanager.edit.containerversions |
请求正文
在请求正文中,请按以下结构提供数据:
{ "quickPreview": boolean, "name": string, "notes": string }
属性名称 | 值 | 说明 | 备注 |
---|---|---|---|
quickPreview |
boolean |
创建此版本可能是为了快速预览,不应加以保存。 | |
name |
string |
要创建的容器版本的名称。 | |
notes |
string |
要创建的容器版本的说明。 |
响应
如果成功,此方法将返回采用以下结构的响应正文:
{ "containerVersion": accounts.containers.versions Resource, "compilerError": boolean }
属性名称 | 值 | 说明 | 备注 |
---|---|---|---|
containerVersion |
nested object |
已创建的容器版本。 | |
compilerError |
boolean |
是否存在编译器错误。 |
示例
注意:此方法的代码示例并未列出所有受支持的编程语言(请参阅客户端库页面,查看受支持的语言列表)。
Java
使用 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
使用 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')
试试看!
请使用下面的 API Explorer 对实时数据调用此方法并查看响应。