Criar e acessar relatórios programados

É possível criar e programar relatórios usando a a interface do usuário do Video 360 API. Por exemplo, os usuários finais podem configurar um relatório diário que mostre ou um relatório mensal que mostra o gasto total.

Criar relatórios programados

Criar um novo relatório programado na guia "Rede de Display e interface de relatórios do Video 360 ou com o método de API queries.create. Detalhes completos em Rede de Display e A funcionalidade de geração de relatórios do Video 360 e como criar novos relatórios podem ser encontrado na Central de Ajuda Site de suporte do Video 360.

Os relatórios podem ser programados na criação usando o campo Repeats na interface e no schedule na API. Esses campos devem ser definidos o intervalo de tempo apropriado.

Depois que o campo adequado for definido, o relatório será gerado de acordo com a programação os relatórios gerados estarão disponíveis para download.

Acessar relatórios programados

Os relatórios programados são gerados como arquivos CSV simples e armazenados automaticamente e com segurança no Google Cloud Storage. Não é possível, no entanto, acessar buckets do Google Cloud Storage que contêm esses arquivos diretamente. Em vez disso, dos arquivos podem ser transferidos manualmente na página da Rede de Display e Interface do Video 360 ou recuperada programaticamente usando URLs pré-autorizados obtidos de a API.

Veja abaixo um exemplo de como usar a API para fazer o download de um arquivo de relatório. Neste exemplo, queries.reports.list é usado com o Parâmetro orderBy para recuperar o relatório mais recente em uma consulta. Depois, O campo Report.reportMetadata.googleCloudStoragePath é usada para localizar o arquivo de relatório e fazer o download do conteúdo para um arquivo CSV local.

Importações obrigatórias:

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;

Exemplo de código:

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

Importações obrigatórias:

from contextlib import closing
from six.moves.urllib.request import urlopen

Exemplo de código:

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