Search in sources :

Example 6 with ReportDownloadResponseException

use of com.google.api.ads.adwords.lib.utils.ReportDownloadResponseException in project googleads-java-lib by googleads.

the class StreamCriteriaReportResults method main.

public static void main(String[] args) {
    AdWordsSession session;
    try {
        // Generate a refreshable OAuth2 credential.
        Credential oAuth2Credential = new OfflineCredentials.Builder().forApi(Api.ADWORDS).fromFile().build().generateCredential();
        // Construct an AdWordsSession.
        session = new AdWordsSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
    } catch (ConfigurationLoadException cle) {
        System.err.printf("Failed to load configuration from the %s file. Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, cle);
        return;
    } catch (ValidationException ve) {
        System.err.printf("Invalid configuration in the %s file. Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, ve);
        return;
    } catch (OAuthException oe) {
        System.err.printf("Failed to create OAuth credentials. Check OAuth settings in the %s file. " + "Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, oe);
        return;
    }
    AdWordsServicesInterface adWordsServices = AdWordsServices.getInstance();
    try {
        runExample(adWordsServices, session);
    } catch (DetailedReportDownloadResponseException dre) {
        // A DetailedReportDownloadResponseException will be thrown if the HTTP status code in the
        // response indicates an error occurred and the response body contains XML with further
        // information, such as the fieldPath and trigger.
        System.err.printf("Report was not downloaded due to a %s with errorText '%s', trigger '%s' and " + "field path '%s'%n", dre.getClass().getSimpleName(), dre.getErrorText(), dre.getTrigger(), dre.getFieldPath());
    } catch (ReportDownloadResponseException rde) {
        // A ReportDownloadResponseException will be thrown if the HTTP status code in the response
        // indicates an error occurred, but the response did not contain further details.
        System.err.printf("Report was not downloaded due to: %s%n", rde);
    } catch (ReportException re) {
        // A ReportException will be thrown if the download failed due to a transport layer exception.
        System.err.printf("Report was not downloaded due to transport layer exception: %s%n", re);
    } catch (IOException ioe) {
        // An IOException in this example indicates that the report's contents could not be read from
        // the response.
        System.err.printf("Report was not read due to an IOException: %s%n", ioe);
    }
}
Also used : Credential(com.google.api.client.auth.oauth2.Credential) ValidationException(com.google.api.ads.common.lib.exception.ValidationException) DetailedReportDownloadResponseException(com.google.api.ads.adwords.lib.utils.DetailedReportDownloadResponseException) AdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession) ConfigurationLoadException(com.google.api.ads.common.lib.conf.ConfigurationLoadException) OAuthException(com.google.api.ads.common.lib.exception.OAuthException) AdWordsServicesInterface(com.google.api.ads.adwords.lib.factory.AdWordsServicesInterface) ReportException(com.google.api.ads.adwords.lib.utils.ReportException) DetailedReportDownloadResponseException(com.google.api.ads.adwords.lib.utils.DetailedReportDownloadResponseException) ReportDownloadResponseException(com.google.api.ads.adwords.lib.utils.ReportDownloadResponseException) IOException(java.io.IOException)

Example 7 with ReportDownloadResponseException

use of com.google.api.ads.adwords.lib.utils.ReportDownloadResponseException in project googleads-java-lib by googleads.

the class ParallelReportDownload method main.

public static void main(String[] args) {
    ImmutableAdWordsSession session;
    try {
        // Generate a refreshable OAuth2 credential.
        Credential oAuth2Credential = new OfflineCredentials.Builder().forApi(Api.ADWORDS).fromFile().build().generateCredential();
        // Construct an ImmutableAdWordsSession to use as a prototype when creating a session for each
        // managed customer.
        session = new AdWordsSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).buildImmutable();
    } catch (ConfigurationLoadException cle) {
        System.err.printf("Failed to load configuration from the %s file. Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, cle);
        return;
    } catch (ValidationException ve) {
        System.err.printf("Invalid configuration in the %s file. Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, ve);
        return;
    } catch (OAuthException oe) {
        System.err.printf("Failed to create OAuth credentials. Check OAuth settings in the %s file. " + "Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, oe);
        return;
    }
    AdWordsServicesInterface adWordsServices = AdWordsServices.getInstance();
    // Adjust these values as needed.
    int numberOfThreads = 5;
    int maxElapsedSecondsPerCustomer = 60 * 5;
    try {
        runExample(adWordsServices, session, numberOfThreads, maxElapsedSecondsPerCustomer);
    } catch (DetailedReportDownloadResponseException dre) {
        // A DetailedReportDownloadResponseException will be thrown if the HTTP status code in the
        // response indicates an error occurred and the response body contains XML with further
        // information, such as the fieldPath and trigger.
        System.err.printf("Report was not downloaded due to a %s with errorText '%s', trigger '%s' and " + "field path '%s'%n", dre.getClass().getSimpleName(), dre.getErrorText(), dre.getTrigger(), dre.getFieldPath());
    } catch (ApiException apiException) {
        // ApiException is the base class for most exceptions thrown by an API request. Instances
        // of this exception have a message and a collection of ApiErrors that indicate the
        // type and underlying cause of the exception. Every exception object in the adwords.axis
        // packages will return a meaningful value from toString
        // 
        // ApiException extends RemoteException, so this catch block must appear before the
        // catch block for RemoteException.
        System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
        if (apiException.getErrors() != null) {
            int i = 0;
            for (ApiError apiError : apiException.getErrors()) {
                System.err.printf("  Error %d: %s%n", i++, apiError);
            }
        }
    } catch (RemoteException re) {
        System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
    } catch (ReportDownloadResponseException rde) {
        // A ReportDownloadResponseException will be thrown if the HTTP status code in the response
        // indicates an error occurred, but the response did not contain further details.
        System.err.printf("Report was not downloaded due to: %s%n", rde);
    } catch (ReportException re) {
        // A ReportException will be thrown if the download failed due to a transport layer exception.
        System.err.printf("Report was not downloaded due to transport layer exception: %s%n", re);
    } catch (IOException ioe) {
        // An IOException in this example indicates that the report's contents could not be read from
        // the response.
        System.err.printf("Report was not read due to an IOException: %s%n", ioe);
    } catch (InterruptedException ie) {
        System.err.printf("Thread was interrupted while waiting for reports to complete: %s%n", ie);
    } catch (ValidationException ve) {
        System.err.printf("Failed to create a session for a customer: %s%n", ve);
    }
}
Also used : ImmutableAdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession.ImmutableAdWordsSession) Credential(com.google.api.client.auth.oauth2.Credential) ValidationException(com.google.api.ads.common.lib.exception.ValidationException) DetailedReportDownloadResponseException(com.google.api.ads.adwords.lib.utils.DetailedReportDownloadResponseException) SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) OAuthException(com.google.api.ads.common.lib.exception.OAuthException) AdWordsServicesInterface(com.google.api.ads.adwords.lib.factory.AdWordsServicesInterface) IOException(java.io.IOException) ConfigurationLoadException(com.google.api.ads.common.lib.conf.ConfigurationLoadException) ReportException(com.google.api.ads.adwords.lib.utils.ReportException) ApiError(com.google.api.ads.adwords.axis.v201809.cm.ApiError) DetailedReportDownloadResponseException(com.google.api.ads.adwords.lib.utils.DetailedReportDownloadResponseException) ReportDownloadResponseException(com.google.api.ads.adwords.lib.utils.ReportDownloadResponseException) RemoteException(java.rmi.RemoteException) ApiException(com.google.api.ads.adwords.axis.v201809.cm.ApiException)

Aggregations

ReportDownloadResponseException (com.google.api.ads.adwords.lib.utils.ReportDownloadResponseException)7 IOException (java.io.IOException)7 DetailedReportDownloadResponseException (com.google.api.ads.adwords.lib.utils.DetailedReportDownloadResponseException)6 ReportException (com.google.api.ads.adwords.lib.utils.ReportException)6 ConfigurationLoadException (com.google.api.ads.common.lib.conf.ConfigurationLoadException)6 ValidationException (com.google.api.ads.common.lib.exception.ValidationException)6 AdWordsServicesInterface (com.google.api.ads.adwords.lib.factory.AdWordsServicesInterface)5 OAuthException (com.google.api.ads.common.lib.exception.OAuthException)5 AdWordsSession (com.google.api.ads.adwords.lib.client.AdWordsSession)4 Credential (com.google.api.client.auth.oauth2.Credential)4 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)2 ImmutableAdWordsSession (com.google.api.ads.adwords.lib.client.AdWordsSession.ImmutableAdWordsSession)2 RemoteException (java.rmi.RemoteException)2 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)1 ApiError (com.google.api.ads.adwords.axis.v201809.cm.ApiError)1 ManagedCustomer (com.google.api.ads.adwords.axis.v201809.mcm.ManagedCustomer)1 ReportingConfiguration (com.google.api.ads.adwords.lib.client.reporting.ReportingConfiguration)1 ReportDefinition (com.google.api.ads.adwords.lib.jaxb.v201809.ReportDefinition)1 Selector (com.google.api.ads.adwords.lib.jaxb.v201809.Selector)1 RawReportDownloadResponse (com.google.api.ads.adwords.lib.utils.RawReportDownloadResponse)1