自定义指标:list

需要授权

列出用户有权访问的自定义指标。 立即试用查看示例

请求

HTTP 请求

GET https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/customMetrics

参数

参数名称 说明
路径参数
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#customMetrics",
  "username": string,
  "totalResults": integer,
  "startIndex": integer,
  "itemsPerPage": integer,
  "previousLink": string,
  "nextLink": string,
  "items": [
    management.customMetrics Resource
  ]
}
属性名称 说明 备注
kind string 集合类型。
username string 已验证用户的电子邮件 ID
totalResults integer 查询的结果总数,与响应中的结果数无关。
startIndex integer 资源的起始索引,默认为 1,或者通过 start-index 查询参数指定。
itemsPerPage integer 响应所能包含的资源数量上限,与返回的实际资源数无关。其值的范围为 1 至 1000,默认为 1000,否则通过 max-results 查询参数指定。
items[] list 自定义指标集合。

示例

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

Java

使用 Java 客户端库

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

/**
 * This request lists all custom metrics for the authorized user.
 */
try {
  CustomMetrics metrics = analytics.management.customMetrics
      .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 metrics object.
 * The following code shows how to iterate through them.
 */
for (CustomMetric metric : metrics.getItems()) {
  System.out.println("Metric Kind: " + metric.getKind());
  System.out.println("Metric Id: " + metric.getId());
  System.out.println("Account ID: " + metric.getAccountId());
  System.out.println("Property ID: " + metric.getWebPropertyId());
  System.out.println("Metric Name: " + metric.getName());
  System.out.println("Metric Index: " + metric.getIndex());
  System.out.println("Metric Scope: " + metric.getScope());
  System.out.println("Metric Active: " + metric.getActive());
  System.out.println("Metric Type: " + metric.getType());
  System.out.println("Metric Created: " + metric.getCreated());
  System.out.println("Metric Updated: " + metric.getUpdated());
}

Python

使用 Python 客户端库

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

# This request lists all custom metrics for the authorized user.
try:
  metrics = analytics.management().customMetrics().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 metrics object.
# The following code shows how to iterate through them.
for metric in metrics.get('items', []):
  print 'Metric Kind = %s' % metric.get('kind')
  print 'Metric Id = %s' % metric.get('id')
  print 'Account ID = %s' % metric.get('accountId')
  print 'Property ID = %s' % metric.get('webPropertyId')
  print 'Metric Name = %s' % metric.get('name')
  print 'Metric Index = %s' % metric.get('index')
  print 'Metric Scope = %s' % metric.get('scope')
  print 'Metric Active = %s' % metric.get('active')
  print 'Metric Type = %s' % metric.get('type')
  print 'Metric Created = %s' % metric.get('created')
  print 'Metric Updated = %s' % metric.get('updated')

立即试用!

请使用下面的 API Explorer 针对实时数据调用此方法并查看响应。或者,您还可以尝试使用独立的 Explorer