创建和访问定期报告

您可以使用 Google 展示广告网络和Video 360 界面或 API。例如,最终用户可以设置每日报告, 展示次数或显示总支出的每月报表。

创建定期生成的报告

在“展示广告”和Video 360 报告界面或 (使用 queries.create API 方法)。有关完整详情,请访问: 展示广告与Video 360 的报告功能和创建新报告的方式 可在展示广告和Video 360 支持网站

您可以使用界面中的 Repeats 字段以及 schedule 字段。这些字段应设置为 适当的时间间隔。

设置好相应的字段后,此报告将按计划生成, 生成的报表即可下载

访问定期生成的报告

定期生成的报告会生成为简单的 CSV 文件,并会自动存储 安全地存储在 Google Cloud Storage 中不过,您无法访问 直接包含这些文件的 Google Cloud Storage 存储分区。相反, 文件都可以从 Display &Video 360 中手动下载Video 360 界面或检索到 使用从以下网站获取的预授权网址以编程方式 该 API。

下文提供了使用 API 下载报告文件的示例。在本课中, 例如,queries.reports.listorderBy 参数,用于检索最新报告 。然后, Report.reportMetadata.googleCloudStoragePath字段为 用于找到报告文件并将其内容下载到本地 CSV 文件。

必需的导入:

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
);
}

必需的导入:

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)
$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);
}