Custom Dimensions: list

Cần có uỷ quyền

Liệt kê các phương diện tuỳ chỉnh mà người dùng có quyền truy cập. Thử ngay hoặc xem ví dụ.

Yêu cầu

Yêu cầu HTTP

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

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 cho các phương diện tuỳ chỉnh cần truy xuất.
webPropertyId string Mã thuộc tính web cho các phương diện tuỳ chỉnh cần truy xuất.
Tham số truy vấn không bắt buộc
max-results integer Số lượng phương diện tuỳ chỉnh tối đa cần đưa vào phản hồi này.
start-index integer Chỉ mục của thực thể đầu tiên cần truy xuất. Sử dụng thông số này làm cơ chế phân trang cùng với thông số kết quả tối đa.

Ủ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/analytics.readonly
https://www.googleapis.com/auth/analytics

Nội dung yêu cầu

Khô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ề nội dung phản hồi có cấu trúc như sau:

{
  "kind": "analytics#customDimensions",
  "username": string,
  "totalResults": integer,
  "startIndex": integer,
  "itemsPerPage": integer,
  "previousLink": string,
  "nextLink": string,
  "items": [
    management.customDimensions Resource
  ]
}
Tên tài sản Giá trị Nội dung mô tả Ghi chú
kind string Loại bộ sưu tập.
username string Mã email của người dùng đã xác thực
totalResults integer Tổng số kết quả cho truy vấn, bất kể số lượng kết quả trong phản hồi.
startIndex integer Chỉ mục bắt đầu của tài nguyên, là 1 theo mặc định hoặc được chỉ định khác bởi tham số truy vấn chỉ mục bắt đầu.
itemsPerPage integer Số lượng tài nguyên tối đa mà phản hồi có thể chứa, bất kể số lượng tài nguyên thực tế được trả về. Giá trị của nó dao động từ 1 đến 1000 với giá trị là 1000 theo mặc định hoặc được chỉ định bởi tham số truy vấn kết quả tối đa.
items[] list Tập hợp phương diện tuỳ chỉnh.

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 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

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

Hãy dùng thử!

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. Ngoài ra, hãy dùng thử Trình khám phá độc lập.