Uploads: list

Cần có uỷ quyền

Liệt kê các tệp tải lên mà người dùng có quyền truy cập. Thử ngay hoặc xem ví dụ.

Ngoài các thông số chuẩn, phương thức này còn hỗ trợ các thông số được liệt kê trong bảng thông số.

Yêu cầu

Yêu cầu HTTP

GET https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/customDataSources/customDataSourceId/uploads

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 để truy xuất tệp tải lên.
customDataSourceId string Mã nguồn dữ liệu tuỳ chỉnh cho tệp tải lên cần truy xuất.
webPropertyId string Mã thuộc tính web cho tệp tải lên cần truy xuất.
Tham số truy vấn không bắt buộc
max-results integer Số lượt tải lên tối đa được đưa vào phản hồi này.
start-index integer Chỉ mục dựa trên 1 của lần tải lên đầu tiê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
https://www.googleapis.com/auth/analytics.edit
https://www.googleapis.com/auth/analytics.readonly

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#uploads",
  "totalResults": integer,
  "startIndex": integer,
  "itemsPerPage": integer,
  "previousLink": string,
  "nextLink": string,
  "items": [
    management.uploads 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.
totalResults integer Tổng số kết quả cho truy vấn, bất kể số lượng tài nguyên trong kết quả.
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 Danh sách các tệp đã tải lên.

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.
 * See the Data Import Developer Guide for details.
 */

/*
 * Example #1:
 * Requests a list of all uploads for the authorized user.
 */
try {
  Uploads uploads = analytics.management().uploads().list("123456",
      "UA-123456-1", "122333444455555").execute();
} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}

/*
 * Example #2:
 * The results of the list method are stored in the uploads object.
 * The following code shows how to iterate through them.
 */
for (Upload upload : uploads.getItems()) {
  System.out.println("Uploads Id            = " + upload.getId());
  System.out.println("Upload Kind           = " + upload.getKind());
  System.out.println("Account Id            = " + upload.getAccountId());
  System.out.println("Custom Data Source Id = " + upload.getCustomDataSourceId());
  System.out.println("Upload Status         = " + upload.getStatus() + "\n");
}

1.199

Sử dụng thư viện ứng dụng PHP.

/**
 * Note: This code assumes you have an authorized Analytics service object.
 * See the Data Import Developer Guide for details.
 */

/**
 * Example #1:
 * Requests a list of all uploads for the authorized user.
 */
try {
  $uploads = $analytics->management_uploads->listManagementuploads('123456',
      'UA-123456-1', '122333444455555');

} catch (apiServiceException $e) {
  print 'There was an Analytics API service error '
      . $e->getCode() . ':' . $e->getMessage();

} catch (apiException $e) {
  print 'There was a general API error '
      . $e->getCode() . ':' . $e->getMessage();
}


/**
 * Example #2:
 * The results of the list method are stored in the uploads object.
 * The following code shows how to iterate through them.
 */
foreach ($uploads->getItems() as $upload) {

  $html = <<<HTML
<pre>
Upload id     = {$upload->getId()}
Upload kind   = {$upload->getKind()}
Account id    = {$upload->getAccountId()}
Data set id   = {$upload->getCustomDataSourceId()}
Upload status = {$upload->getStatus()}
</pre>

HTML;
  print $html;
}



Python

Sử dụng thư viện ứng dụng Python.

# Note: This code assumes you have an authorized Analytics service object.
# See the Uploads Dev Guide for details.

# Example #1:
# Requests a list of all uploads for the authorized user.
try:
  uploads = analytics.management().uploads().list(
      accountId='123456',
      webPropertyId='UA-123456-1',
      customDataSourceId='ABCDEFG123abcDEF123'
  ).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))


# Example #2:
# The results of the list method are stored in the uploads object.
# The following code shows how to iterate through them.
for upload in uploads.get('items', []):
  print 'Upload Id             = %s' % upload.get('id')
  print 'Upload Kind           = %s' % upload.get('kind')
  print 'Account Id            = %s' % upload.get('accountId')
  print 'Custom Data Source Id = %s' % upload.get('customDataSourceId')
  print 'Upload Status         = %s\n' % upload.get('status')



JavaScript

Sử dụng thư viện ứng dụng JavaScript.

/*
 * Note: This code assumes you have an authorized Analytics client object.
 * See the Data Import Developer Guide for details.
 */

/*
 * Example 1:
 * Requests a list of all Uploads for the authorized user.
 */
function listUploads() {
  var request = gapi.client.analytics.management.uploads.list({
    'accountId': '123456',
    'webPropertyId': 'UA-123456-1',
    'customDataSourceId': 'ABCDEFG123abcDEF123',
  });
  request.execute(printUploads);
}

/*
 * Example 2:
 * The results of the list method are passed as the results object.
 * The following code shows how to iterate through them.
 */
function printUploads(results) {
  if (results && !results.error) {
    var uploads = results.items;
    for (var i = 0, upload; upload = uploads[i]; i++) {
      console.log('Upload Id: ' + upload.id);
      console.log('Upload Kind: ' + upload.kind);
      console.log('Account Id: ' + upload.accountId);
      console.log('Data Set Id: ' + upload.customDataSourceId);
      console.log('Upload Status: ' + upload.status);
    }
  }
}

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.