Search in sources :

Example 36 with CustomTargetingServiceInterface

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

the class UpdateCustomTargetingValues method runExample.

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

Aggregations

CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202108.CustomTargetingServiceInterface)9 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202111.CustomTargetingServiceInterface)9 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202202.CustomTargetingServiceInterface)9 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202205.CustomTargetingServiceInterface)9 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)8 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)8 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)8 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)8 ArrayList (java.util.ArrayList)8 CustomTargetingKey (com.google.api.ads.admanager.axis.v202108.CustomTargetingKey)5 CustomTargetingValue (com.google.api.ads.admanager.axis.v202108.CustomTargetingValue)5 CustomTargetingKey (com.google.api.ads.admanager.axis.v202111.CustomTargetingKey)5 CustomTargetingValue (com.google.api.ads.admanager.axis.v202111.CustomTargetingValue)5 CustomTargetingKey (com.google.api.ads.admanager.axis.v202202.CustomTargetingKey)5 CustomTargetingValue (com.google.api.ads.admanager.axis.v202202.CustomTargetingValue)5 CustomTargetingKey (com.google.api.ads.admanager.axis.v202205.CustomTargetingKey)5 CustomTargetingValue (com.google.api.ads.admanager.axis.v202205.CustomTargetingValue)5 CustomTargetingKeyPage (com.google.api.ads.admanager.axis.v202108.CustomTargetingKeyPage)4 CustomTargetingValuePage (com.google.api.ads.admanager.axis.v202108.CustomTargetingValuePage)4 CustomTargetingKeyPage (com.google.api.ads.admanager.axis.v202111.CustomTargetingKeyPage)4