Search in sources :

Example 26 with LineItem

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

the class PauseLineItems method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param lineItemId the ID of the line item to pause.
 * @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 select a line item.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", lineItemId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get line items by statement.
        LineItemPage page = lineItemService.getLineItemsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (LineItem lineItem : page.getResults()) {
                System.out.printf("%d) Line item with ID %d will be paused.%n", i++, lineItem.getId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of line items to be paused: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        com.google.api.ads.admanager.axis.v202202.PauseLineItems action = new com.google.api.ads.admanager.axis.v202202.PauseLineItems();
        // Perform action.
        UpdateResult result = lineItemService.performLineItemAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of line items paused: %d%n", result.getNumChanges());
        } else {
            System.out.println("No line items were paused.");
        }
    }
}
Also used : LineItemServiceInterface(com.google.api.ads.admanager.axis.v202202.LineItemServiceInterface) LineItem(com.google.api.ads.admanager.axis.v202202.LineItem) LineItemPage(com.google.api.ads.admanager.axis.v202202.LineItemPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) UpdateResult(com.google.api.ads.admanager.axis.v202202.UpdateResult)

Example 27 with LineItem

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

the class GetRecentlyUpdatedLineItems 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 {
    LineItemServiceInterface lineItemService = adManagerServices.get(session, LineItemServiceInterface.class);
    // Create a statement to select line items.
    StatementBuilder statementBuilder = new StatementBuilder().where("lastModifiedDateTime >= :lastModifiedDateTime").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("lastModifiedDateTime", DateTimes.toDateTime(Instant.now().minus(Duration.standardDays(1L)), "America/New_York"));
    // Retrieve a small amount of line items at a time, paging through
    // until all line items have been retrieved.
    int totalResultSetSize = 0;
    do {
        LineItemPage page = lineItemService.getLineItemsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            // Print out some information for each line item.
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (LineItem lineItem : page.getResults()) {
                System.out.printf("%d) Line item with ID %d and name '%s' was found.%n", i++, lineItem.getId(), lineItem.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : LineItemServiceInterface(com.google.api.ads.admanager.axis.v202202.LineItemServiceInterface) LineItemPage(com.google.api.ads.admanager.axis.v202202.LineItemPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) LineItem(com.google.api.ads.admanager.axis.v202202.LineItem)

Example 28 with LineItem

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

the class GetAllLineItems 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 LineItemService.
    LineItemServiceInterface lineItemService = adManagerServices.get(session, LineItemServiceInterface.class);
    // Create a statement to select all line items.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get line items by statement.
        LineItemPage page = lineItemService.getLineItemsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (LineItem lineItem : page.getResults()) {
                System.out.printf("%d) Line item with ID %d and name '%s' was found.%n", i++, lineItem.getId(), lineItem.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : LineItemServiceInterface(com.google.api.ads.admanager.axis.v202108.LineItemServiceInterface) LineItemPage(com.google.api.ads.admanager.axis.v202108.LineItemPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) LineItem(com.google.api.ads.admanager.axis.v202108.LineItem)

Example 29 with LineItem

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

the class GetRecentlyUpdatedLineItems 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 {
    LineItemServiceInterface lineItemService = adManagerServices.get(session, LineItemServiceInterface.class);
    // Create a statement to select line items.
    StatementBuilder statementBuilder = new StatementBuilder().where("lastModifiedDateTime >= :lastModifiedDateTime").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("lastModifiedDateTime", DateTimes.toDateTime(Instant.now().minus(Duration.standardDays(1L)), "America/New_York"));
    // Retrieve a small amount of line items at a time, paging through
    // until all line items have been retrieved.
    int totalResultSetSize = 0;
    do {
        LineItemPage page = lineItemService.getLineItemsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            // Print out some information for each line item.
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (LineItem lineItem : page.getResults()) {
                System.out.printf("%d) Line item with ID %d and name '%s' was found.%n", i++, lineItem.getId(), lineItem.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : LineItemServiceInterface(com.google.api.ads.admanager.axis.v202108.LineItemServiceInterface) LineItemPage(com.google.api.ads.admanager.axis.v202108.LineItemPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) LineItem(com.google.api.ads.admanager.axis.v202108.LineItem)

Example 30 with LineItem

use of com.google.api.ads.admanager.axis.v202202.LineItem 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.v202108.LineItemServiceInterface) LineItemPage(com.google.api.ads.admanager.axis.v202108.LineItemPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) LineItem(com.google.api.ads.admanager.axis.v202108.LineItem)

Aggregations

LineItem (com.google.api.ads.admanager.axis.v202108.LineItem)10 LineItem (com.google.api.ads.admanager.axis.v202111.LineItem)10 LineItem (com.google.api.ads.admanager.axis.v202202.LineItem)10 LineItemServiceInterface (com.google.api.ads.admanager.axis.v202108.LineItemServiceInterface)9 LineItemServiceInterface (com.google.api.ads.admanager.axis.v202111.LineItemServiceInterface)9 LineItemServiceInterface (com.google.api.ads.admanager.axis.v202202.LineItemServiceInterface)9 Random (java.util.Random)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 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 AdUnitTargeting (com.google.api.ads.admanager.axis.v202108.AdUnitTargeting)4 CreativePlaceholder (com.google.api.ads.admanager.axis.v202108.CreativePlaceholder)4 Goal (com.google.api.ads.admanager.axis.v202108.Goal)4 InventoryTargeting (com.google.api.ads.admanager.axis.v202108.InventoryTargeting)4 Size (com.google.api.ads.admanager.axis.v202108.Size)4 Targeting (com.google.api.ads.admanager.axis.v202108.Targeting)4 AdUnitTargeting (com.google.api.ads.admanager.axis.v202111.AdUnitTargeting)4