Search in sources :

Example 51 with ApiException

use of com.google.api.ads.admanager.axis.v202111.ApiException in project googleads-java-lib by googleads.

the class ArchiveProposalLineItems method main.

public static void main(String[] args) {
    AdManagerSession session;
    try {
        // Generate a refreshable OAuth2 credential.
        Credential oAuth2Credential = new OfflineCredentials.Builder().forApi(Api.AD_MANAGER).fromFile().build().generateCredential();
        // Construct a AdManagerSession.
        session = new AdManagerSession.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;
    }
    AdManagerServices adManagerServices = new AdManagerServices();
    ArchiveProposalLineItemsParams params = new ArchiveProposalLineItemsParams();
    if (!params.parseArguments(args)) {
        // Either pass the required parameters for this example on the command line, or insert them
        // into the code here. See the parameter class definition above for descriptions.
        params.proposalLineItemId = Long.parseLong("INSERT_PROPOSAL_LINE_ITEM_ID_HERE");
    }
    try {
        runExample(adManagerServices, session, params.proposalLineItemId);
    } 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 admanager.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);
    }
}
Also used : Credential(com.google.api.client.auth.oauth2.Credential) ValidationException(com.google.api.ads.common.lib.exception.ValidationException) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) ConfigurationLoadException(com.google.api.ads.common.lib.conf.ConfigurationLoadException) OAuthException(com.google.api.ads.common.lib.exception.OAuthException) ApiError(com.google.api.ads.admanager.axis.v202111.ApiError) RemoteException(java.rmi.RemoteException) AdManagerSession(com.google.api.ads.admanager.lib.client.AdManagerSession) AdManagerServices(com.google.api.ads.admanager.axis.factory.AdManagerServices) ApiException(com.google.api.ads.admanager.axis.v202111.ApiException)

Example 52 with ApiException

use of com.google.api.ads.admanager.axis.v202111.ApiException in project googleads-java-lib by googleads.

the class GetAllProposalLineItems method main.

public static void main(String[] args) {
    AdManagerSession session;
    try {
        // Generate a refreshable OAuth2 credential.
        Credential oAuth2Credential = new OfflineCredentials.Builder().forApi(Api.AD_MANAGER).fromFile().build().generateCredential();
        // Construct a AdManagerSession.
        session = new AdManagerSession.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;
    }
    AdManagerServices adManagerServices = new AdManagerServices();
    try {
        runExample(adManagerServices, session);
    } 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 admanager.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);
    }
}
Also used : Credential(com.google.api.client.auth.oauth2.Credential) ValidationException(com.google.api.ads.common.lib.exception.ValidationException) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) ConfigurationLoadException(com.google.api.ads.common.lib.conf.ConfigurationLoadException) OAuthException(com.google.api.ads.common.lib.exception.OAuthException) ApiError(com.google.api.ads.admanager.axis.v202111.ApiError) RemoteException(java.rmi.RemoteException) AdManagerSession(com.google.api.ads.admanager.lib.client.AdManagerSession) AdManagerServices(com.google.api.ads.admanager.axis.factory.AdManagerServices) ApiException(com.google.api.ads.admanager.axis.v202111.ApiException)

Example 53 with ApiException

use of com.google.api.ads.admanager.axis.v202111.ApiException in project googleads-java-lib by googleads.

the class UpdateProposalLineItems method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param proposalLineItemId the ID of the proposal line item to update.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, long proposalLineItemId) throws RemoteException {
    // Get the ProposalLineItemService.
    ProposalLineItemServiceInterface proposalLineItemService = adManagerServices.get(session, ProposalLineItemServiceInterface.class);
    // Create a statement to select a proposal line item.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", proposalLineItemId);
    // Get the proposal line item.
    ProposalLineItemPage page = proposalLineItemService.getProposalLineItemsByStatement(statementBuilder.toStatement());
    ProposalLineItem proposalLineItem = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
    // Update the proposal line item's note field.
    proposalLineItem.setInternalNotes("Proposal line item ready for submission.");
    // Update the proposal line item on the server.
    ProposalLineItem[] proposalLineItems = proposalLineItemService.updateProposalLineItems(new ProposalLineItem[] { proposalLineItem });
    for (ProposalLineItem updatedProposalLineItem : proposalLineItems) {
        System.out.printf("Proposal line item with ID %d and name '%s' was updated.%n", updatedProposalLineItem.getId(), updatedProposalLineItem.getName());
    }
}
Also used : ProposalLineItem(com.google.api.ads.admanager.axis.v202111.ProposalLineItem) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) ProposalLineItemPage(com.google.api.ads.admanager.axis.v202111.ProposalLineItemPage) ProposalLineItemServiceInterface(com.google.api.ads.admanager.axis.v202111.ProposalLineItemServiceInterface)

Example 54 with ApiException

use of com.google.api.ads.admanager.axis.v202111.ApiException in project googleads-java-lib by googleads.

the class GetAllOrders method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    // Get the OrderService.
    OrderServiceInterface orderService = adManagerServices.get(session, OrderServiceInterface.class);
    // Create a statement to select all orders.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get orders by statement.
        OrderPage page = orderService.getOrdersByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Order order : page.getResults()) {
                System.out.printf("%d) Order with ID %d and name '%s' was found.%n", i++, order.getId(), order.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : Order(com.google.api.ads.admanager.axis.v202111.Order) OrderPage(com.google.api.ads.admanager.axis.v202111.OrderPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) OrderServiceInterface(com.google.api.ads.admanager.axis.v202111.OrderServiceInterface)

Example 55 with ApiException

use of com.google.api.ads.admanager.axis.v202111.ApiException in project googleads-java-lib by googleads.

the class GetAllPlacements method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    // Get the PlacementService.
    PlacementServiceInterface placementService = adManagerServices.get(session, PlacementServiceInterface.class);
    // Create a statement to get all placements.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get placements by statement.
        PlacementPage page = placementService.getPlacementsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Placement placement : page.getResults()) {
                System.out.printf("%d) Placement with ID %d and name '%s' was found.%n", i++, placement.getId(), placement.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : PlacementPage(com.google.api.ads.admanager.axis.v202111.PlacementPage) Placement(com.google.api.ads.admanager.axis.v202111.Placement) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) PlacementServiceInterface(com.google.api.ads.admanager.axis.v202111.PlacementServiceInterface)

Aggregations

ConfigurationLoadException (com.google.api.ads.common.lib.conf.ConfigurationLoadException)490 OAuthException (com.google.api.ads.common.lib.exception.OAuthException)490 ValidationException (com.google.api.ads.common.lib.exception.ValidationException)490 RemoteException (java.rmi.RemoteException)490 AdManagerServices (com.google.api.ads.admanager.axis.factory.AdManagerServices)487 AdManagerSession (com.google.api.ads.admanager.lib.client.AdManagerSession)487 Credential (com.google.api.client.auth.oauth2.Credential)487 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)233 ApiException (com.google.api.ads.admanager.axis.v202202.ApiException)164 ApiException (com.google.api.ads.admanager.axis.v202108.ApiException)163 ApiException (com.google.api.ads.admanager.axis.v202111.ApiException)163 ApiError (com.google.api.ads.admanager.axis.v202202.ApiError)163 ApiError (com.google.api.ads.admanager.axis.v202108.ApiError)162 ApiError (com.google.api.ads.admanager.axis.v202111.ApiError)162 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)117 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)117 IOException (java.io.IOException)59 Random (java.util.Random)25 UpdateResult (com.google.api.ads.admanager.axis.v202111.UpdateResult)18 NetworkServiceInterface (com.google.api.ads.admanager.axis.v202111.NetworkServiceInterface)15