Search in sources :

Example 36 with LineItemServiceInterface

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

the class UpdateLineItems method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param lineItemId the ID of the 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 lineItemId) throws RemoteException {
    // Get the LineItemService.
    LineItemServiceInterface lineItemService = adManagerServices.get(session, LineItemServiceInterface.class);
    // Create a statement to only select a single line item by ID.
    StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", lineItemId);
    // Get the line item.
    LineItemPage page = lineItemService.getLineItemsByStatement(statementBuilder.toStatement());
    LineItem lineItem = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
    // Update the line item's priority to High if possible.
    if (lineItem.getLineItemType().equals(LineItemType.STANDARD)) {
        lineItem.setPriority(6);
        // Update the line item on the server.
        LineItem[] lineItems = lineItemService.updateLineItems(new LineItem[] { lineItem });
        for (LineItem updatedLineItem : lineItems) {
            System.out.printf("Line item with ID %d and name '%s' was updated.%n", updatedLineItem.getId(), updatedLineItem.getName());
        }
    } else {
        System.out.println("No line items were updated.");
    }
}
Also used : LineItemServiceInterface(com.google.api.ads.admanager.axis.v202205.LineItemServiceInterface) LineItemPage(com.google.api.ads.admanager.axis.v202205.LineItemPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder) LineItem(com.google.api.ads.admanager.axis.v202205.LineItem)

Aggregations

Random (java.util.Random)12 LineItem (com.google.api.ads.admanager.axis.v202108.LineItem)9 LineItemServiceInterface (com.google.api.ads.admanager.axis.v202108.LineItemServiceInterface)9 LineItem (com.google.api.ads.admanager.axis.v202111.LineItem)9 LineItemServiceInterface (com.google.api.ads.admanager.axis.v202111.LineItemServiceInterface)9 LineItem (com.google.api.ads.admanager.axis.v202202.LineItem)9 LineItemServiceInterface (com.google.api.ads.admanager.axis.v202202.LineItemServiceInterface)9 LineItem (com.google.api.ads.admanager.axis.v202205.LineItem)9 LineItemServiceInterface (com.google.api.ads.admanager.axis.v202205.LineItemServiceInterface)9 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)6 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)6 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)6 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)6 LineItemPage (com.google.api.ads.admanager.axis.v202108.LineItemPage)6 LineItemPage (com.google.api.ads.admanager.axis.v202111.LineItemPage)6 LineItemPage (com.google.api.ads.admanager.axis.v202202.LineItemPage)6 LineItemPage (com.google.api.ads.admanager.axis.v202205.LineItemPage)4 AdUnitTargeting (com.google.api.ads.admanager.axis.v202108.AdUnitTargeting)3 CreativePlaceholder (com.google.api.ads.admanager.axis.v202108.CreativePlaceholder)3 Goal (com.google.api.ads.admanager.axis.v202108.Goal)3