Search in sources :

Example 1 with CustomTargetingServiceInterface

use of com.google.api.ads.admanager.axis.v202111.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.v202202.CustomTargetingValue) CustomTargetingServiceInterface(com.google.api.ads.admanager.axis.v202202.CustomTargetingServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) CustomTargetingValuePage(com.google.api.ads.admanager.axis.v202202.CustomTargetingValuePage)

Example 2 with CustomTargetingServiceInterface

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

the class GetPredefinedCustomTargetingKeysAndValues method getPredefinedCustomTargetingKeyIds.

public static List<Long> getPredefinedCustomTargetingKeyIds(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    List<Long> customTargetingKeyIds = new ArrayList<>();
    CustomTargetingServiceInterface customTargetingService = adManagerServices.get(session, CustomTargetingServiceInterface.class);
    // Create a statement to get predefined custom targeting keys.
    StatementBuilder statementBuilder = new StatementBuilder().where("type = :type").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("type", CustomTargetingKeyType.PREDEFINED.toString());
    // 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) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (CustomTargetingKey customTargetingKey : page.getResults()) {
                System.out.printf("%d) Custom targeting key with ID %d, name '%s', and " + "display name '%s' was found.%n", i++, customTargetingKey.getId(), customTargetingKey.getName(), customTargetingKey.getDisplayName());
                customTargetingKeyIds.add(customTargetingKey.getId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    return customTargetingKeyIds;
}
Also used : CustomTargetingServiceInterface(com.google.api.ads.admanager.axis.v202111.CustomTargetingServiceInterface) CustomTargetingKey(com.google.api.ads.admanager.axis.v202111.CustomTargetingKey) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) ArrayList(java.util.ArrayList) CustomTargetingKeyPage(com.google.api.ads.admanager.axis.v202111.CustomTargetingKeyPage)

Example 3 with CustomTargetingServiceInterface

use of com.google.api.ads.admanager.axis.v202111.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.v202111.CustomTargetingValue) CustomTargetingServiceInterface(com.google.api.ads.admanager.axis.v202111.CustomTargetingServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) CustomTargetingValuePage(com.google.api.ads.admanager.axis.v202111.CustomTargetingValuePage)

Example 4 with CustomTargetingServiceInterface

use of com.google.api.ads.admanager.axis.v202111.CustomTargetingServiceInterface 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.v202111.CustomTargetingServiceInterface) CustomTargetingKey(com.google.api.ads.admanager.axis.v202111.CustomTargetingKey) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) CustomTargetingKeyPage(com.google.api.ads.admanager.axis.v202111.CustomTargetingKeyPage)

Example 5 with CustomTargetingServiceInterface

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

the class CreateCustomTargetingKeysAndValues 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 CustomTargetingService.
    CustomTargetingServiceInterface customTargetingService = adManagerServices.get(session, CustomTargetingServiceInterface.class);
    // Create predefined key.
    CustomTargetingKey genderKey = new CustomTargetingKey();
    genderKey.setDisplayName("gender");
    genderKey.setName("g" + new Random().nextInt(1000));
    genderKey.setType(CustomTargetingKeyType.PREDEFINED);
    // Create predefined key that may be used for content targeting.
    CustomTargetingKey genreKey = new CustomTargetingKey();
    genreKey.setDisplayName("genre");
    genreKey.setName("genre" + new Random().nextInt(1000));
    genreKey.setType(CustomTargetingKeyType.PREDEFINED);
    // Create free-form key.
    CustomTargetingKey carModelKey = new CustomTargetingKey();
    carModelKey.setDisplayName("car model");
    carModelKey.setName("c" + new Random().nextInt(1000));
    carModelKey.setType(CustomTargetingKeyType.FREEFORM);
    // Create the custom targeting keys on the server.
    CustomTargetingKey[] customTargetingKeys = customTargetingService.createCustomTargetingKeys(new CustomTargetingKey[] { genderKey, genreKey, carModelKey });
    for (CustomTargetingKey createdCustomTargetingKey : customTargetingKeys) {
        System.out.printf("A custom targeting key with ID %d, name '%s', and display name " + "'%s' was created.%n", createdCustomTargetingKey.getId(), createdCustomTargetingKey.getName(), createdCustomTargetingKey.getDisplayName());
    }
    // Set the created custom targeting keys.
    genderKey = customTargetingKeys[0];
    genreKey = customTargetingKeys[1];
    carModelKey = customTargetingKeys[2];
    // Create custom targeting value for the predefined gender key.
    CustomTargetingValue genderMaleValue = new CustomTargetingValue();
    genderMaleValue.setCustomTargetingKeyId(genderKey.getId());
    genderMaleValue.setDisplayName("male");
    // Name is set to 1 so that the actual name can be hidden from website
    // users.
    genderMaleValue.setName("1");
    genderMaleValue.setMatchType(CustomTargetingValueMatchType.EXACT);
    CustomTargetingValue genderFemaleValue = new CustomTargetingValue();
    genderFemaleValue.setCustomTargetingKeyId(genderKey.getId());
    genderFemaleValue.setDisplayName("female");
    // Name is set to 2 so that the actual name can be hidden from website
    // users.
    genderFemaleValue.setName("2");
    genderFemaleValue.setMatchType(CustomTargetingValueMatchType.EXACT);
    // Create custom targeting value for the predefined genre key.
    CustomTargetingValue genreComedyValue = new CustomTargetingValue();
    genreComedyValue.setCustomTargetingKeyId(genreKey.getId());
    genreComedyValue.setDisplayName("comedy");
    genreComedyValue.setName("comedy");
    genreComedyValue.setMatchType(CustomTargetingValueMatchType.EXACT);
    CustomTargetingValue genreDramaValue = new CustomTargetingValue();
    genreDramaValue.setCustomTargetingKeyId(genreKey.getId());
    genreDramaValue.setDisplayName("drama");
    genreDramaValue.setName("drama");
    genreDramaValue.setMatchType(CustomTargetingValueMatchType.EXACT);
    // Create custom targeting value for the free-form car model key. These are
    // values that would be suggested in the UI or can be used when targeting
    // with a FreeFormCustomCriteria.
    CustomTargetingValue carModelHondaValue = new CustomTargetingValue();
    carModelHondaValue.setCustomTargetingKeyId(carModelKey.getId());
    carModelHondaValue.setDisplayName("~honda");
    carModelHondaValue.setName("honda");
    // A match type of broad will match anything including "honda",
    // i.e. "~honda".
    carModelHondaValue.setMatchType(CustomTargetingValueMatchType.BROAD);
    // Create the custom targeting values on the server.
    CustomTargetingValue[] customTargetingValues = customTargetingService.createCustomTargetingValues(new CustomTargetingValue[] { genderMaleValue, genderFemaleValue, genreComedyValue, genreDramaValue, carModelHondaValue });
    for (CustomTargetingValue createdCustomTargetingValue : customTargetingValues) {
        System.out.printf("A custom targeting value with ID %d, belonging to key with ID %d, " + "name '%s' and display name '%s' was created.%n", createdCustomTargetingValue.getId(), createdCustomTargetingValue.getCustomTargetingKeyId(), createdCustomTargetingValue.getName(), createdCustomTargetingValue.getDisplayName());
    }
}
Also used : CustomTargetingValue(com.google.api.ads.admanager.axis.v202111.CustomTargetingValue) CustomTargetingServiceInterface(com.google.api.ads.admanager.axis.v202111.CustomTargetingServiceInterface) CustomTargetingKey(com.google.api.ads.admanager.axis.v202111.CustomTargetingKey) Random(java.util.Random)

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 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 ArrayList (java.util.ArrayList)6 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 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 CustomTargetingValuePage (com.google.api.ads.admanager.axis.v202111.CustomTargetingValuePage)4 CustomTargetingKeyPage (com.google.api.ads.admanager.axis.v202202.CustomTargetingKeyPage)4 CustomTargetingValuePage (com.google.api.ads.admanager.axis.v202202.CustomTargetingValuePage)4 Random (java.util.Random)3