Search in sources :

Example 11 with CreativeWrapperPage

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

the class GetAllCreativeWrappers 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 CreativeWrapperService.
    CreativeWrapperServiceInterface creativeWrapperService = adManagerServices.get(session, CreativeWrapperServiceInterface.class);
    // Create a statement to select all creative wrappers.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get creative wrappers by statement.
        CreativeWrapperPage page = creativeWrapperService.getCreativeWrappersByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (CreativeWrapper creativeWrapper : page.getResults()) {
                System.out.printf("%d) Creative wrapper with ID %d applying to label ID %d was found.%n", i++, creativeWrapper.getId(), creativeWrapper.getLabelId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : CreativeWrapper(com.google.api.ads.admanager.axis.v202111.CreativeWrapper) CreativeWrapperPage(com.google.api.ads.admanager.axis.v202111.CreativeWrapperPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) CreativeWrapperServiceInterface(com.google.api.ads.admanager.axis.v202111.CreativeWrapperServiceInterface)

Example 12 with CreativeWrapperPage

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

the class DeactivateCreativeWrappersForLabel method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param labelId the ID of the creative wrapper label to deactivate.
 * @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 labelId) throws RemoteException {
    // Get the CreativeWrapperService.
    CreativeWrapperServiceInterface creativeWrapperService = adManagerServices.get(session, CreativeWrapperServiceInterface.class);
    // Create a statement to select the active creative wrappers for the
    // given label.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE status = :status AND labelId = :labelId").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("status", CreativeWrapperStatus.ACTIVE.toString()).withBindVariableValue("labelId", labelId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get creative wrappers by statement.
        CreativeWrapperPage page = creativeWrapperService.getCreativeWrappersByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (CreativeWrapper creativeWrapper : page.getResults()) {
                System.out.printf("%d) Creative wrapper with ID %d applying to label ID" + " %d will be deactivated.%n", i++, creativeWrapper.getId(), creativeWrapper.getLabelId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of creative wrappers to be deactivated: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        DeactivateCreativeWrappers action = new DeactivateCreativeWrappers();
        // Perform action.
        UpdateResult result = creativeWrapperService.performCreativeWrapperAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of creative wrappers deactivated: %d%n", result.getNumChanges());
        } else {
            System.out.println("No creative wrappers were deactivated.");
        }
    }
}
Also used : CreativeWrapper(com.google.api.ads.admanager.axis.v202111.CreativeWrapper) CreativeWrapperPage(com.google.api.ads.admanager.axis.v202111.CreativeWrapperPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) DeactivateCreativeWrappers(com.google.api.ads.admanager.axis.v202111.DeactivateCreativeWrappers) CreativeWrapperServiceInterface(com.google.api.ads.admanager.axis.v202111.CreativeWrapperServiceInterface) UpdateResult(com.google.api.ads.admanager.axis.v202111.UpdateResult)

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)4 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)4 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)4 CreativeWrapper (com.google.api.ads.admanager.axis.v202108.CreativeWrapper)4 CreativeWrapperPage (com.google.api.ads.admanager.axis.v202108.CreativeWrapperPage)4 CreativeWrapperServiceInterface (com.google.api.ads.admanager.axis.v202108.CreativeWrapperServiceInterface)4 CreativeWrapper (com.google.api.ads.admanager.axis.v202111.CreativeWrapper)4 CreativeWrapperPage (com.google.api.ads.admanager.axis.v202111.CreativeWrapperPage)4 CreativeWrapperServiceInterface (com.google.api.ads.admanager.axis.v202111.CreativeWrapperServiceInterface)4 CreativeWrapper (com.google.api.ads.admanager.axis.v202202.CreativeWrapper)4 CreativeWrapperPage (com.google.api.ads.admanager.axis.v202202.CreativeWrapperPage)4 CreativeWrapperServiceInterface (com.google.api.ads.admanager.axis.v202202.CreativeWrapperServiceInterface)4 DeactivateCreativeWrappers (com.google.api.ads.admanager.axis.v202108.DeactivateCreativeWrappers)1 UpdateResult (com.google.api.ads.admanager.axis.v202108.UpdateResult)1 DeactivateCreativeWrappers (com.google.api.ads.admanager.axis.v202111.DeactivateCreativeWrappers)1 UpdateResult (com.google.api.ads.admanager.axis.v202111.UpdateResult)1 DeactivateCreativeWrappers (com.google.api.ads.admanager.axis.v202202.DeactivateCreativeWrappers)1 UpdateResult (com.google.api.ads.admanager.axis.v202202.UpdateResult)1