// Get the ReportService.
ReportServiceInterface reportService = user.getService(DfpService.V201306.REPORT_SERVICE);
// Create report job.
ReportJob reportJob = new ReportJob();
// Create report query.
ReportQuery reportQuery = new ReportQuery();
reportQuery.setDateRangeType(DateRangeType.LAST_MONTH);
reportQuery.setDimensions(new Dimension[] {Dimension.ORDER_ID, Dimension.ORDER_NAME});
reportQuery.setColumns(new Column[] {Column.MERGED_AD_SERVER_IMPRESSIONS,
Column.MERGED_AD_SERVER_CLICKS, Column.MERGED_AD_SERVER_CTR,
Column.MERGED_AD_SERVER_CPM_AND_CPC_REVENUE,
Column.MERGED_AD_SERVER_WITHOUT_CPD_AVERAGE_ECPM});
reportJob.setReportQuery(reportQuery);
// Run report job.
reportJob = reportService.runReportJob(reportJob);
do {
System.out.println("Report with ID '" + reportJob.getId() + "' is still running.");
Thread.sleep(30000);
// Get report job.
reportJob = reportService.getReportJob(reportJob.getId());
} while (reportJob.getReportJobStatus() == ReportJobStatus.IN_PROGRESS);
if (reportJob.getReportJobStatus() == ReportJobStatus.FAILED) {
System.out.println("Report job with ID '" + reportJob.getId()
+ "' failed to finish successfully.");
} else {
System.out.println("Report job with ID '" + reportJob.getId()
+ "' completed successfully.");
}
} catch (Exception e) {
e.printStackTrace();
}