예약 보고서 작성 및 액세스

Google Display & Video 360 UI 또는 API를 사용하여 보고서를 만들고 예약할 수 있습니다. 예를 들어 최종 사용자는 어제의 노출수를 표시하는 일일 보고서 또는 총 지출을 보여주는 월간 보고서를 설정할 수 있습니다.

예약된 보고서 생성

Display & Video 360 보고 인터페이스 또는 queries.create API 메서드를 사용하여 새 예약 보고서를 만듭니다. Display & Video 360의 보고 기능과 새 보고서를 만드는 방법에 관한 자세한 내용은 Display & Video 360 지원 사이트에서 확인할 수 있습니다.

UI의 Repeats 필드와 API의 schedule 필드를 사용하여 보고서 생성 일정을 예약할 수 있습니다. 이러한 필드는 적절한 시간 간격으로 설정해야 합니다.

적절한 필드가 설정되면 이 보고서가 해당 일정에 따라 실행되고 생성된 보고서를 다운로드할 수 있습니다.

예약된 보고서 액세스

예약된 보고서는 간단한 CSV 파일로 생성되며 Google Cloud Storage에 자동으로 안전하게 저장됩니다. 그러나 이러한 파일이 포함된 Google Cloud Storage 버킷에 직접 액세스할 수는 없습니다. 대신 Display & Video 360 UI에서 수동으로 파일을 다운로드하거나 API에서 가져온 사전 승인된 URL을 사용하여 프로그래매틱 방식으로 가져올 수 있습니다.

다음은 API를 사용하여 보고서 파일을 다운로드하는 예입니다. 이 예에서 queries.reports.list는 쿼리에 속한 가장 최근 보고서를 검색하기 위해 orderBy 매개변수와 함께 사용됩니다. 그런 다음 Report.reportMetadata.googleCloudStoragePath 필드를 사용하여 보고서 파일을 찾고 그 콘텐츠를 로컬 CSV 파일로 다운로드합니다.

Java

필수 가져오기:

import com.google.api.client.googleapis.media.MediaHttpDownloader;
import com.google.api.client.googleapis.util.Utils;
import com.google.api.client.http.GenericUrl;
import com.google.api.services.doubleclickbidmanager.DoubleClickBidManager;
import com.google.api.services.doubleclickbidmanager.model.ListReportsResponse;
import com.google.api.services.doubleclickbidmanager.model.Report;
import java.io.FileOutputStream;
import java.io.OutputStream;

코드 예시:

long queryId = query-id;

// Call the API, listing the reports under the given queryId from most to
// least recent.
ListReportsResponse reportListResponse =
    service
        .queries()
        .reports()
        .list(queryId)
        .setOrderBy("key.reportId desc")
        .execute();

// Iterate over returned reports, stopping once finding a report that
// finished generating successfully.
Report mostRecentReport = null;
if (reportListResponse.getReports() != null) {
  for (Report report : reportListResponse.getReports()) {
    if (report.getMetadata().getStatus().getState().equals("DONE")) {
      mostRecentReport = report;
      break;
    }
  }
} else {
  System.out.format("No reports exist for query Id %s.\n", queryId);
}

// Download report file of most recent finished report found.
if (mostRecentReport != null) {
  // Retrieve GCS URL from report object.
  GenericUrl reportUrl =
      new GenericUrl(mostRecentReport.getMetadata().getGoogleCloudStoragePath());

  // Build filename.
  String filename =
      mostRecentReport.getKey().getQueryId() + "_"
          + mostRecentReport.getKey().getReportId() + ".csv";

  // Download the report file.
  try (OutputStream output = new FileOutputStream(filename)) {
    MediaHttpDownloader downloader =
        new MediaHttpDownloader(Utils.getDefaultTransport(), null);
    downloader.download(reportUrl, output);
  }
  System.out.format("Download of file %s complete.\n", filename);
} else {
  System.out.format(
      "There are no completed report files to download for query Id %s.\n",
      queryId);
}

Python

필수 가져오기:

from contextlib import closing
from six.moves.urllib.request import urlopen

코드 예시:

query_id = query-id

# Call the API, listing the reports under the given queryId from most to
# least recent.
response = service.queries().reports().list(queryId=query_id, orderBy="key.reportId desc").execute()

# Iterate over returned reports, stopping once finding a report that
# finished generating successfully.
most_recent_report = None
if response['reports']:
  for report in response['reports']:
    if report['metadata']['status']['state'] == 'DONE':
      most_recent_report = report
      break
else:
  print('No reports exist for query Id %s.' % query_id)

# Download report file of most recent finished report found.
if most_recent_report != None:
  # Retrieve GCS URL from report object.
  report_url = most_recent_report['metadata']['googleCloudStoragePath']

  # Build filename.
  output_file = '%s_%s.csv' % (report['key']['queryId'], report['key']['reportId'])

  # Download the report file.
  with open(output_file, 'wb') as output:
    with closing(urlopen(report_url)) as url:
      output.write(url.read())
  print('Download of file %s complete.' % output_file)
else:
  print('There are no completed report files to download for query Id %s.' % query_id)

2,399필리핀

$queryId = query-id;

// Call the API, listing the reports under the given queryId from most to
// least recent.
$optParams = array('orderBy' => "key.reportId desc");
$response = $service->queries_reports->listQueriesReports($queryId, $optParams);

// Iterate over returned reports, stopping once finding a report that
// finished generating successfully.
$mostRecentReport = null;
if (!empty($response->getReports())) {
  foreach ($response->getReports() as $report) {
    if ($report->metadata->status->state == "DONE") {
      $mostRecentReport = $report;
      break;
    }
  }
} else {
  printf('<p>No reports exist for query ID %s.</p>', $queryId);
}

// Download report file of most recent finished report found.
if ($mostRecentReport != null) {
  // Build filename.
  $filename = $mostRecentReport->key->queryId . '_' . $mostRecentReport->key->reportId . '.csv';

  // Download the report file.
  file_put_contents($filename, fopen($mostRecentReport->metadata->googleCloudStoragePath, 'r'));
  printf('<p>Download of file %s complete.</p>', $filename);
} else {
  printf('<p>There are no completed report files to download for query Id %s.</p>', $queryId);
}