use of com.google.api.ads.common.lib.exception.AuthenticationException in project googleads-java-lib by googleads.
the class AdHocReportDownloadHelperImpl method downloadReport.
@Override
public RawReportDownloadResponse downloadReport(ReportRequest reportRequest) throws ReportException {
try {
String apiVersion = reportRequest.getApiVersion();
String downloadUrl = generateReportUrl(apiVersion);
HttpRequestFactory requestFactory = reportRequestFactoryHelper.getHttpRequestFactory(downloadUrl, apiVersion);
ReportBodyProvider reportBodyProvider = reportBodyProviderFactory.getReportBodyProvider(reportRequest);
HttpRequest httpRequest = requestFactory.buildPostRequest(new GenericUrl(downloadUrl), reportBodyProvider.getHttpContent());
HttpResponse response = httpRequest.execute();
Charset charSet = REPORT_CHARSET;
// default to REPORT_CHARSET, we have to inspect the MediaType ourselves.
if (response.getMediaType() != null && response.getMediaType().getCharsetParameter() != null) {
charSet = response.getMediaType().getCharsetParameter();
}
return new RawReportDownloadResponse(response.getStatusCode(), response.getContent(), charSet, reportRequest.getDownloadFormat().name());
} catch (MalformedURLException e) {
throw new ReportException("Created invalid report download URL.", e);
} catch (IOException e) {
throw new ReportException("Problem sending data to report download server.", e);
} catch (AuthenticationException e) {
throw new ReportException("Problem with OAuth authorization.", e);
}
}
Aggregations