Empty Eeport in the API

4 views
Skip to first unread message

Gustavo Mazo

unread,
12:40 PM (5 hours ago) 12:40 PM
to Google Ad Manager API Forum
Hello, what's up?

I'm having a problem pulling reports from the API.
In the Google Ad Manager dashboard, when generating a report, the information appears correctly, click impressions...

When I pull it through the API, I don't get any information, just the column headings.

What could be wrong with this process?

Code:
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();
$session = (new AdManagerSessionBuilder())->fromFile()->withOAuth2Credential($oAuth2Credential)->build();
$adManagerServices = new AdManagerServices();
// Criação da consulta de relatório.
$reportQuery = new ReportQuery();
$reportQuery->setDimensions([Dimension::DATE]); // Dimensão Data
$reportQuery->setColumns([
Column::AD_SERVER_IMPRESSIONS,
Column::AD_SERVER_CLICKS,
Column::AD_SERVER_CTR,
Column::AD_SERVER_CPM_AND_CPC_REVENUE
]); // Adicione as métricas que você deseja incluir
// Configuração de data personalizada para os últimos 7 dias.
$today = new DateTime('now', new DateTimeZone('America/Sao_Paulo'));
$sevenDaysAgo = new DateTime('-7 days', new DateTimeZone('America/Sao_Paulo'));
$reportQuery->setDateRangeType(DateRangeType::CUSTOM_DATE);
$reportQuery->setStartDate(AdManagerDateTimes::fromDateTime($sevenDaysAgo)->getDate());
$reportQuery->setEndDate(AdManagerDateTimes::fromDateTime($today)->getDate());
// Criação e execução do relatório.
$reportJob = new ReportJob();
$reportJob->setReportQuery($reportQuery);
$reportService = $adManagerServices->get($session, ReportService::class);
$reportJob = $reportService->runReportJob($reportJob);
// Monitoramento do status do relatório.
$reportDownloader = new ReportDownloader($reportService, $reportJob->getId());
// Espera até que o relatório esteja pronto.
while (true) {
$status = $reportService->getReportJobStatus($reportJob->getId());
if ($status === ReportJobStatus::COMPLETED) {
break;
} elseif ($status === ReportJobStatus::FAILED) {
throw new \RuntimeException('O relatório falhou ao ser gerado.');
}
sleep(10); // Espera 10 segundos antes de verificar o status novamente.
}
// Download do relatório.
$filePath = tempnam(sys_get_temp_dir(), 'report-') . '.csv';
$reportDownloader->downloadReport(ExportFormat::CSV_DUMP, $filePath);
// Leitura do relatório.
$reportContent = file_get_contents($filePath);
unlink($filePath); // Limpeza do arquivo temporário.
return new Response($reportContent, 200, [
'Content-Type' => 'text/csv',
'Content-Disposition' => 'attachment; filename="report.csv"',
]);

Ad Manager API Forum Advisor

unread,
1:26 PM (4 hours ago) 1:26 PM
to gustav...@igoalmais.com.br, google-doubleclick...@googlegroups.com
Hi,

Thank you for contacting the Ad Manager API support team.

I have reviewed the information provided and understand that you have retrieved an empty response via the API. Please note that if there is no data for the particular dates with the dimensions and columns used in the report then the results will be empty.

If you are thinking that there should be data instead of the empty results, could you please provide us with the following information for further analysis:
  • Complete SOAP request and response logs from API (SOAP logging must be enabled).
  • UserService.getCurrentUser (if unable, you may just provide the email address used to make API requests).
  • Network code 
  • Confirm that you are seeing the same empty data via the UI or only with the API?
  • If you are seeing the data from the UI, please share it with the downloaded report and the report id.
You can send the details via Reply privately to the author option, or direct private reply to this email.

 
This message is in relation to case "ref:!00D1U01174p.!5004Q02vEI1g:ref" (ADR-00259995)

Thanks,
 
Google Logo Ad Manager API Team

 

Reply all
Reply to author
Forward
0 new messages