我試圖從DFP廣告管理系統通過API和Google提供的PHP庫https://github.com/googleads/googleads-php-lib/從Google Analytics獲得一份非常基本的報告。我已經嘗試在UI中創建查詢並從API中獲取ReportQuery並運行它(根據https://developers.google.com/doubleclick-publishers/docs/reporting#retrieving_a_saved_reportquery)以及創建臨時查詢。所有創建請求好吧,這似乎暗示查詢驗證沒問題。其他的API請求,我測試過,做工精細,包括獲取的行項目等Google DFP API ReportService失敗,沒有顯着的錯誤消息
相關代碼如下列表:
$statementBuilder = (new StatementBuilder())
->where('AD_UNIT_NAME like \'prebid_\'');
# Create report query.
$reportQuery = new ReportQuery();
$reportQuery->setDimensions([
Dimension::AD_UNIT_NAME,
Dimension::CUSTOM_CRITERIA,
Dimension::DATE
]);
$reportQuery->setColumns([
Column::TOTAL_INVENTORY_LEVEL_IMPRESSIONS,
Column::TOTAL_INVENTORY_LEVEL_WITHOUT_CPD_AVERAGE_ECPM
]);
$reportQuery->setStatement($statementBuilder->toStatement());
$reportQuery->setAdUnitView(ReportQueryAdUnitView::TOP_LEVEL);
$reportQuery->setDateRangeType(DateRangeType::YESTERDAY);
# Create report job.
$reportJob = new ReportJob();
$reportJob->setReportQuery($reportQuery);
# Run report job.
$reportJob = $reportService->runReportJob($reportJob);
# Create report downloader.
$reportDownloader = new ReportDownloader($reportService, $reportJob->getId(), POLL_TIME_SECONDS);
# Wait for the report to be ready.
$reportDownloader->waitForReportToFinish();
# Change to your file location.
$filePath = sprintf('%s.csv.gz', tempnam(sys_get_temp_dir(),
'delivery-report-'));
printf("Downloading report to %s ...\n", $filePath);
# Download the report.
$reportDownloader->downloadReport('CSV_DUMP', $filePath);
下面是錯誤信息,我從該API獲取:
PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Cannot download report 1834923393 because it has a status of FAILED.' in ~/test/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Dfp/Util/v201611/ReportDownloader.php:146
Stack trace:
#0 ~/test/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Dfp/Util/v201611/ReportDownloader.php(116): Google\AdsApi\Dfp\Util\v201611\ReportDownloader->getDownloadUrl('CSV_DUMP')
#1 ~/test/dfp/get_prebid_unit_data.php(85): Google\AdsApi\Dfp\Util\v201611\ReportDownloader->downloadReport('CSV_DUMP', '/tmp/delivery-r...')
#2 {main}
thrown in ~/test/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Dfp/Util/v201611/ReportDownloader.php on line 146
功能評論[狀態](https://github.com/googleads/googleads-php-lib/blob/5eea2f7fb65fd07f0413eb2e33bc2e7563c43078/src/Google/AdsApi/Dfp/Util/v201611/ReportDownloader.php# L112)當報告失敗時引發異常,所以您可能需要該服務提供的其他工具。可悲的是,我在某個Google論壇中發現的潛在工作超時:/並且沒有支持文檔(在他們自己的回購示例中,如果報告失敗,它只是打印失敗......)看起來你可能不是能夠從API獲得有用的失敗原因。 – Jmills