إنشاء التقارير المجدولة والوصول إليها

يمكنك إنشاء التقارير وجدولتها باستخدام "شبكة Google الإعلانية" واجهة مستخدم الفيديو 360 أو واجهة برمجة التطبيقات. على سبيل المثال، يمكن للمستخدمين النهائيين إعداد تقرير يومي يعرض مرات الظهور أو تقرير شهري يعرض إجمالي الإنفاق.

إنشاء تقارير مجدوَلة

إنشاء تقرير مجدوَل جديد في "الشبكة الإعلانية" واجهة إعداد تقارير الفيديو 360 أو باستخدام طريقة واجهة برمجة التطبيقات queries.create. التفاصيل الكاملة على العرض يمكن الاطّلاع على وظائف إعداد التقارير في Video 360 وكيفية إنشاء تقارير جديدة الموجودة في شاشة العرض الموقع الإلكتروني الخاص بفريق دعم "إعلانات الفيديو 360"

يمكن جدولة التقارير عند إنشائها باستخدام الحقل Repeats في واجهة المستخدم schedule في واجهة برمجة التطبيقات. يجب ضبط هذه الحقول على الفاصل الزمني المناسب.

بعد تعيين الحقل المناسب، سيتم تشغيل هذا التقرير وفقًا لهذا الجدول الزمني ستكون التقارير التي تم إنشاؤها متاحة للتنزيل.

الوصول إلى التقارير المجدوَلة

يتم إنشاء التقارير المجدوَلة على هيئة ملفات CSV بسيطة ويتم تخزينها تلقائيًا. بأمان في Google Cloud Storage ومع ذلك، لا يمكن الوصول إلى حِزم Google Cloud Storage التي تحتوي على هذه الملفات مباشرةً. بدلاً من ذلك، يمكن تنزيلها يدويًا من "الشاشة" واجهة مستخدم الفيديو 360 أو تم استردادها آليًا باستخدام عناوين URL المعتمَدة مسبقًا التي تم الحصول عليها من واجهة برمجة التطبيقات.

في ما يلي مثال على استخدام واجهة برمجة التطبيقات لتنزيل ملف تقرير. في هذه الدورة، على سبيل المثال، تُستخدم 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)

PHP

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