reportDefinition.setDownloadFormat(DownloadFormat.CSV);
// Enable to allow rows with zero impressions to show.
reportDefinition.setIncludeZeroImpressions(true);
reportDefinition.setSelector(reportSelector);
ReportDownloadResponse response =
new ReportDownloader(session).downloadReport(reportDefinition);
if (response.getHttpStatus() == HttpURLConnection.HTTP_OK) {
FileOutputStream fos = new FileOutputStream(new File(reportFile));
Streams.copy(response.getInputStream(), fos);
fos.close();
System.out.println("Report successfully downloaded: " + reportFile);
} else {
System.out.println("Report was not downloaded. " + response.getHttpStatus() + ": "
+ response.getHttpResponseMessage());
}
}