需要授权
请求
HTTP 请求
GET https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/customDimensions
参数
参数名称 | 值 | 说明 |
---|---|---|
路径参数 | ||
accountId |
string |
要提取的自定义维度的帐号 ID。 |
webPropertyId |
string |
要提取的自定义维度的网络媒体资源 ID。 |
可选的查询参数 | ||
max-results |
integer |
此响应所能包含的自定义维度数量上限。 |
start-index |
integer |
要检索的第一个实体的索引。此参数可与 max-results 参数搭配使用,作为分页机制。 |
授权
此请求需要获得以下至少一个范围的授权(详细了解身份验证和授权)。
范围 |
---|
https://www.googleapis.com/auth/analytics.readonly |
https://www.googleapis.com/auth/analytics |
请求正文
使用此方法时请勿提供请求正文。
响应
如果成功,此方法将返回采用以下结构的响应正文:
{ "kind": "analytics#customDimensions", "username": string, "totalResults": integer, "startIndex": integer, "itemsPerPage": integer, "previousLink": string, "nextLink": string, "items": [ management.customDimensions Resource ] }
属性名称 | 值 | 说明 | 备注 |
---|---|---|---|
kind |
string |
集合类型。 | |
username |
string |
已验证用户的电子邮件 ID | |
totalResults |
integer |
查询的结果总数,与响应中的结果数无关。 | |
startIndex |
integer |
资源的起始索引,默认为 1,或者通过 start-index 查询参数指定。 | |
itemsPerPage |
integer |
响应所能包含的资源数量上限,与返回的实际资源数无关。其值的范围为 1 至 1000,默认为 1000,否则通过 max-results 查询参数指定。 | |
previousLink |
string |
指向此自定义维度集合的上一页的链接。 | |
nextLink |
string |
指向此自定义维度集合的下一页的链接。 | |
items[] |
list |
自定义维度集合。 |
示例
注意:此方法的代码示例并未列出所有受支持的编程语言(请参阅客户端库页面,查看受支持的语言列表)。
Java
使用 Java 客户端库。
/** * Note: This code assumes you have an authorized Analytics service object. */ /** * This request lists all custom dimensions for the authorized user. */ try { CustomDimensions dimensions = analytics.management.customDimensions .list("12345", "UA-12345-1").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 dimensions object. * The following code shows how to iterate through them. */ for (CustomDimension dimension : dimensions.getItems()) { System.out.println("Dimension Kind: " + dimension.getKind()); System.out.println("Dimension Id: " + dimension.getId()); System.out.println("Account ID: " + dimension.getAccountId()); System.out.println("Property ID: " + dimension.getWebPropertyId()); System.out.println("Dimension Name: " + dimension.getName()); System.out.println("Dimension Index: " + dimension.getIndex()); System.out.println("Dimension Scope: " + dimension.getScope()); System.out.println("Dimension Active: " + dimension.getActive()); System.out.println("Dimension Created: " + dimension.getCreated()); System.out.println("Dimension Updated: " + dimension.getUpdated()); }
Python
使用 Python 客户端库。
# Note: This code assumes you have an authorized Analytics service object. # This request lists all custom dimensions for the authorized user. try: dimensions = analytics.management().customDimensions().list( accountId='123456', webPropertyId='UA-123456-1', ).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 dimensions object. # The following code shows how to iterate through them. for dimension in dimensions.get('items', []): print 'Dimension Kind = %s' % dimension.get('kind') print 'Dimension Id = %s' % dimension.get('id') print 'Account ID = %s' % dimension.get('accountId') print 'Property ID = %s' % dimension.get('webPropertyId') print 'Dimension Name = %s' % dimension.get('name') print 'Dimension Index = %s' % dimension.get('index') print 'Dimension Scope = %s' % dimension.get('scope') print 'Dimension Active = %s' % dimension.get('active') print 'Dimension Created = %s' % dimension.get('created') print 'Dimension Updated = %s' % dimension.get('updated')
试试看!
请使用下面的 API Explorer 对实际数据调用此方法,并查看响应。或者,您也可以尝试使用独立的 Explorer。