Search in sources :

Example 1 with AuthenticationException

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);
    }
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) MalformedURLException(java.net.MalformedURLException) HttpRequestFactory(com.google.api.client.http.HttpRequestFactory) AuthenticationException(com.google.api.ads.common.lib.exception.AuthenticationException) HttpResponse(com.google.api.client.http.HttpResponse) Charset(java.nio.charset.Charset) GenericUrl(com.google.api.client.http.GenericUrl) IOException(java.io.IOException)

Aggregations

AuthenticationException (com.google.api.ads.common.lib.exception.AuthenticationException)1 GenericUrl (com.google.api.client.http.GenericUrl)1 HttpRequest (com.google.api.client.http.HttpRequest)1 HttpRequestFactory (com.google.api.client.http.HttpRequestFactory)1 HttpResponse (com.google.api.client.http.HttpResponse)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 Charset (java.nio.charset.Charset)1