يمكنك إنشاء التقارير وجدولتها باستخدام واجهة مستخدم "مساحة العرض والفيديو 360" من Google أو واجهة برمجة التطبيقات. على سبيل المثال، يمكن للمستخدمين النهائيين إعداد تقرير يومي يعرض مرات الظهور التي تمت بالأمس، أو تقرير شهري يعرض إجمالي الإنفاق.
إنشاء التقارير المجدولة
يمكنك إنشاء تقرير مجدول جديد في واجهة إعداد التقارير في "مساحة العرض والفيديو 360" أو
باستخدام طريقة واجهة برمجة التطبيقات queries.create
. يمكنك الاطّلاع على التفاصيل الكاملة حول وظيفة إعداد التقارير في "مساحة العرض والفيديو 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); }