Unsampled Reports: list

需要授權

列出使用者有權存取的未取樣報表。參閱範例

要求

HTTP 要求

GET https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/profiles/profileId/unsampledReports

參數

參數名稱 說明
路徑參數
accountId string 要擷取未取樣報表的帳戶 ID。必須為特定帳戶 ID,且不支援「全部」選項。
profileId string 查看 (設定檔) ID 以擷取未取樣報表。必須是特定的資料檢視 (設定檔) ID,不支援「全部」。
webPropertyId string 用來擷取未取樣報表的網站資源 ID。且必須為指定網站資源 ID,且不支援「全部」參數。
選用查詢參數
max-results integer 此回應中包含的未取樣報表數量上限。
start-index integer 要擷取的第一個未取樣報表的索引。請將這個參數當做分頁機制,並搭配 max-results 參數。

授權

這項要求需要至少下列其中一個範圍的授權 (進一步瞭解驗證和授權)。

範圍
https://www.googleapis.com/auth/analytics
https://www.googleapis.com/auth/analytics.edit
https://www.googleapis.com/auth/analytics.readonly

要求主體

請勿使用這個方法提供要求主體。

回應

如果成功的話,這個方法會傳回回應內文,其結構如下:

{
  "kind": "analytics#unsampledReports",
  "username": string,
  "totalResults": integer,
  "startIndex": integer,
  "itemsPerPage": integer,
  "previousLink": string,
  "nextLink": string,
  "items": [
    management.unsampledReports 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.
 * See the Unsampled Reports Developer Guide for details.
 */

/*
 * Example #1:
 * Requests a list of all unsampled reports for the authorized user.
 */

try {
  UnsampledReports reports = analytics.management().
      unsampledReports().list("123456", "UA-123456-1", "7654321").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 reports object.
 * The following code shows how to iterate through them.
 */
for (UnsampledReport report : reports.getItems()) {
  System.out.println("Account Id = " + report.getAccountId());
  System.out.println("Property Id  = " + report.getWebPropertyId());
  System.out.println("Report Id = " + report.getId());
  System.out.println("Report Title = " + report.getTitle());
  System.out.println("Report Kind = " + report.getKind());
  System.out.println("Report start-date = " + report.getStartDate());
  System.out.println("Report end-date = " + report.getEndDate());
  System.out.println("Report metric = " + report.getMetrics());
  System.out.println("Report dimensions = " + report.getDimensions());
  System.out.println("Report filters = " + report.getFilters());
  System.out.println("Report Status = " + report.getStatus());
  System.out.println("Report downloadType = " + report.getDownloadType());
  DriveDownloadDetails drive = report.getDriveDownloadDetails();
  CloudStorageDownloadDetails cloud = report.getCloudStorageDownloadDetails();
  System.out.println("Drive Document id = " + drive.getDocumentId());
  System.out.println("Cloud Bucket Id = " + cloud.getBucketId());
  System.out.println("Cloud Object Id = " + cloud.getObjectId());
}

PHP

使用 PHP 用戶端程式庫

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

/**
 * Example #1:
 * Requests a list of all unsampled reports for the authorized user.
 */
try {
  $reports = $analytics->management_unsampledReports
      ->listManagementUnsampledReports('123456', 'UA-123456-1', '7654321');

} 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 reports object.
 * The following code shows how to iterate through them.
 */
foreach ($reports->getItems() as $report) {
  $drive = $report->getDriveDownloadDetails();
  $cloud = $report->getCloudStorageDownloadDetails();
  $html = <<<HTML
<pre>
Account Id          = {$report->getAccountId()}
Property Id         = {$report->getWebPropertyId()}
Report Id           = {$report->getId()}
Report Title        = {$report->getTitle()}
Report Kind         = {$report->getKind()}
Report start-date   = {$report->getStartDate()}
Report end-date     = {$report->getEndDate()}
Report metric       = {$report->getMetrics()}
Report dimensions   = {$report->getDimensions()}
Report filters      = {$report->getFilters()}
Report Status       = {$report->getStatus()}
Report downloadType = {$report->getDownloadType()}
Drive Document id   = {$drive->getDocumentId()}
Cloud Bucket Id     = {$cloud->getBucketId()}
Cloud Object Id     = {$cloud->getObjectId()}
</pre>

HTML;
  print $html;
}

Python

使用 Python 用戶端程式庫

# Note: This code assumes you have an authorized Analytics service object.
# See the Unsampled Reports Developers Guide for details.

# Example #1:
# Requests a list of all Unsampled Reports for the authorized user.
try:
  reports = analytics.management().unsampledReports().list(
      accountId='1234567',
      webPropertyId='UA-1234567-1',
      profileId='7654321'
  ).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 reports object.
# The following code shows how to iterate through them.
for report in reports.get('items', []):
  driveDownloadDetails = report.get('driveDownloadDetails', {})
  cloudStorageDownloadDetails = report.get('cloudStorageDownloadDetails', {})

  print 'Account Id            = %s' % report.get('accountId')
  print 'Property Id           = %s' % report.get('webPropertyId')
  print 'Report Id             = %s' % report.get('id')
  print 'Report Title          = %s' % report.get('title')
  print 'Report Kind           = %s' % report.get('kind')
  print 'Report start-date = %s' % report.get('start-date')
  print 'Report end-date = %s' % report.get('end-date')
  print 'Report metrics        = %s' % report.get('metrics')
  print 'Report dimensions = %s' % report.get('dimensions')
  print 'Report filters = %s' % report.get('filters')
  print 'Report Status         = %s\n' % report.get('status')
  print 'Report downloadType = %s' % report.get('downloadType')
  print 'Drive Document Id = %s' % driveDownloadDetails.get('document Id')
  print 'Cloud Bucket Id = %s' % cloudStorageDownloadDetails.get('bucketId')
  print 'Cloud Object Id = %s' % cloudStorageDownloadDetails.get('objectId')
  print 'Report Created = %s' % report.get('created')
  print 'Report Updated = %s' % report.get('updated')






JavaScript

使用 JavaScript 用戶端程式庫

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

/*
 * Example 1:
 * Requests a list of all unsampled reports for the authorized user.
 */
function listUnsampledReports() {
  var request = gapi.client.analytics.management.unsampledReports.list({
    'accountId': '123456',
    'webPropertyId': 'UA-123456-1',
    'profileId': '7654321'
  });
  request.execute(printViews);
}

/*
 * Example 2:
 * The results of the list method are passed as the results object.
 * The following code shows how to iterate through them.
 */
function printUnsampledReports(results) {
  if (results && !results.error) {
    var reports = results.items;
    for (var i = 0, report; report = reports[i]; i++) {
      console.log('Account Id: ' + report.accountId);
      console.log('Property Id: ' + report.webPropertyId);
      console.log('Report Id: ' + report.id);
      console.log('Report Title: ' + report.title);
      console.log('Report Kind: ' + report.kind);
      console.log('Report start-date:' + report.start-date);
      console.log('Report end-date:' + report.end-date);
      console.log('Report metrics: ' + report.metrics);
      console.log('Report dimensions:' + report.dimensions);
      console.log('Report filters: ' + report.filters);
      console.log('Report Status: ' + report.status);
      console.log('Report downloadType: ' + report.downloadType);

      // Drive document details.
      if (report.driveDownloadDetails) {
        var details = report.driveDownloadDetails;
        console.log('Drive doc id: ' + details.documentId);
      }

      // Cloud storage download details.
      if (report.cloudStorageDownloadDetails) {
        var details = report.cloudStorageDownloadDetails;
        console.log('Cloud bucket id: ' + details.bucketId);
        console.log('Cloud object id: ' + details.objectId);
      }

      console.log('Report Created: ' + report.created);
      console.log('Report Updated: ' + report.updated);
    }
  }
}