Search in sources :

Example 16 with CustomTargetingKeyPage

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

the class UpdateCustomTargetingKeys method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param customTargetingKeyId the ID of the custom targeting key 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 customTargetingKeyId) throws RemoteException {
    // Get the CustomTargetingService.
    CustomTargetingServiceInterface customTargetingService = adManagerServices.get(session, CustomTargetingServiceInterface.class);
    // Create a statement to get custom targeting keys.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", customTargetingKeyId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get custom targeting keys by statement.
        CustomTargetingKeyPage page = customTargetingService.getCustomTargetingKeysByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            CustomTargetingKey[] customTargetingKeys = page.getResults();
            totalResultSetSize = page.getTotalResultSetSize();
            // name.
            for (CustomTargetingKey customTargetingKey : customTargetingKeys) {
                if (customTargetingKey.getDisplayName() == null) {
                    customTargetingKey.setDisplayName(customTargetingKey.getName());
                }
                customTargetingKey.setDisplayName(customTargetingKey.getDisplayName() + " (Deprecated)");
            }
            // Update the custom targeting keys on the server.
            customTargetingKeys = customTargetingService.updateCustomTargetingKeys(customTargetingKeys);
            for (CustomTargetingKey updatedCustomTargetingKey : customTargetingKeys) {
                System.out.printf("Custom targeting key with ID %d, name '%s', and display name " + "'%s' was updated.%n", updatedCustomTargetingKey.getId(), updatedCustomTargetingKey.getName(), updatedCustomTargetingKey.getDisplayName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
}
Also used : CustomTargetingServiceInterface(com.google.api.ads.admanager.axis.v202205.CustomTargetingServiceInterface) CustomTargetingKey(com.google.api.ads.admanager.axis.v202205.CustomTargetingKey) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder) CustomTargetingKeyPage(com.google.api.ads.admanager.axis.v202205.CustomTargetingKeyPage)

Aggregations

ArrayList (java.util.ArrayList)8 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 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)4 CustomTargetingKey (com.google.api.ads.admanager.axis.v202108.CustomTargetingKey)4 CustomTargetingKeyPage (com.google.api.ads.admanager.axis.v202108.CustomTargetingKeyPage)4 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202108.CustomTargetingServiceInterface)4 CustomTargetingKey (com.google.api.ads.admanager.axis.v202111.CustomTargetingKey)4 CustomTargetingKeyPage (com.google.api.ads.admanager.axis.v202111.CustomTargetingKeyPage)4 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202111.CustomTargetingServiceInterface)4 CustomTargetingKey (com.google.api.ads.admanager.axis.v202202.CustomTargetingKey)4 CustomTargetingKeyPage (com.google.api.ads.admanager.axis.v202202.CustomTargetingKeyPage)4 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202202.CustomTargetingServiceInterface)4 CustomTargetingKey (com.google.api.ads.admanager.axis.v202205.CustomTargetingKey)4 CustomTargetingKeyPage (com.google.api.ads.admanager.axis.v202205.CustomTargetingKeyPage)4 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202205.CustomTargetingServiceInterface)4 UpdateResult (com.google.api.ads.admanager.axis.v202108.UpdateResult)1 UpdateResult (com.google.api.ads.admanager.axis.v202111.UpdateResult)1 UpdateResult (com.google.api.ads.admanager.axis.v202202.UpdateResult)1