Search in sources :

Example 1 with LineItemPage

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

the class GetLineItemsThatNeedCreatives 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("isMissingCreatives = :isMissingCreatives").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("isMissingCreatives", true);
    // 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 2 with LineItemPage

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

Example 3 with LineItemPage

use of com.google.api.ads.admanager.axis.v202202.LineItemPage 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.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 4 with LineItemPage

use of com.google.api.ads.admanager.axis.v202202.LineItemPage 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.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 5 with LineItemPage

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

the class GetLineItemsThatNeedCreatives 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("isMissingCreatives = :isMissingCreatives").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("isMissingCreatives", true);
    // 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)

Aggregations

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 LineItem (com.google.api.ads.admanager.axis.v202108.LineItem)6 LineItemPage (com.google.api.ads.admanager.axis.v202108.LineItemPage)6 LineItemServiceInterface (com.google.api.ads.admanager.axis.v202108.LineItemServiceInterface)6 LineItem (com.google.api.ads.admanager.axis.v202111.LineItem)6 LineItemPage (com.google.api.ads.admanager.axis.v202111.LineItemPage)6 LineItemServiceInterface (com.google.api.ads.admanager.axis.v202111.LineItemServiceInterface)6 LineItem (com.google.api.ads.admanager.axis.v202202.LineItem)6 LineItemPage (com.google.api.ads.admanager.axis.v202202.LineItemPage)6 LineItemServiceInterface (com.google.api.ads.admanager.axis.v202202.LineItemServiceInterface)6 ArrayList (java.util.ArrayList)3 BaseCustomFieldValue (com.google.api.ads.admanager.axis.v202108.BaseCustomFieldValue)1 CustomFieldServiceInterface (com.google.api.ads.admanager.axis.v202108.CustomFieldServiceInterface)1 CustomFieldValue (com.google.api.ads.admanager.axis.v202108.CustomFieldValue)1 DropDownCustomFieldValue (com.google.api.ads.admanager.axis.v202108.DropDownCustomFieldValue)1 NumberValue (com.google.api.ads.admanager.axis.v202108.NumberValue)1 UpdateResult (com.google.api.ads.admanager.axis.v202108.UpdateResult)1 BaseCustomFieldValue (com.google.api.ads.admanager.axis.v202111.BaseCustomFieldValue)1