Search in sources :

Example 46 with Statement

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

the class DeleteCustomTargetingValues method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param customTargetingValueId the ID of the custom targeting value to delete.
 * @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 select custom targeting value.
    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();
            int i = page.getStartIndex();
            for (CustomTargetingValue customTargetingValue : page.getResults()) {
                System.out.printf("%d) Custom targeting value with ID %d" + " will be deleted.%n", i++, customTargetingValue.getId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of custom targeting values to be deleted: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        com.google.api.ads.admanager.axis.v202108.DeleteCustomTargetingValues action = new com.google.api.ads.admanager.axis.v202108.DeleteCustomTargetingValues();
        // Perform action.
        UpdateResult result = customTargetingService.performCustomTargetingValueAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of custom targeting values deleted: %d%n", result.getNumChanges());
        } else {
            System.out.println("No custom targeting values deleted.");
        }
    }
}
Also used : CustomTargetingServiceInterface(com.google.api.ads.admanager.axis.v202108.CustomTargetingServiceInterface) CustomTargetingValue(com.google.api.ads.admanager.axis.v202108.CustomTargetingValue) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) CustomTargetingValuePage(com.google.api.ads.admanager.axis.v202108.CustomTargetingValuePage) UpdateResult(com.google.api.ads.admanager.axis.v202108.UpdateResult)

Example 47 with Statement

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

the class GetPredefinedCustomTargetingKeysAndValues 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 {
    CustomTargetingServiceInterface customTargetingService = adManagerServices.get(session, CustomTargetingServiceInterface.class);
    // Get all predefined custom targeting keys.
    List<Long> customTargetingKeyIds = getPredefinedCustomTargetingKeyIds(adManagerServices, session);
    // Create a statement to select custom targeting values.
    StatementBuilder statementBuilder = new StatementBuilder().where("customTargetingKeyId = :customTargetingKeyId").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    int totalResultsCounter = 0;
    for (Long customTargetingKeyId : customTargetingKeyIds) {
        // Set the custom targeting key ID to select from.
        statementBuilder.withBindVariableValue("customTargetingKeyId", customTargetingKeyId);
        // Retrieve a small amount of custom targeting values at a time, paging through
        // until all custom targeting values have been retrieved.
        int totalResultSetSize = 0;
        statementBuilder.offset(0);
        do {
            CustomTargetingValuePage page = customTargetingService.getCustomTargetingValuesByStatement(statementBuilder.toStatement());
            if (page.getResults() != null) {
                // Print out some information for each custom targeting value.
                totalResultSetSize = page.getTotalResultSetSize();
                for (CustomTargetingValue customTargetingValue : page.getResults()) {
                    System.out.printf("%d) Custom targeting value with ID %d, name '%s', display name '%s', " + "and custom targeting key ID %d was found.%n", totalResultsCounter++, customTargetingValue.getId(), customTargetingValue.getName(), customTargetingValue.getDisplayName(), customTargetingValue.getCustomTargetingKeyId());
                }
            }
            statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while (statementBuilder.getOffset() < totalResultSetSize);
    }
    System.out.printf("Number of results found: %d%n", totalResultsCounter);
}
Also used : CustomTargetingValue(com.google.api.ads.admanager.axis.v202108.CustomTargetingValue) CustomTargetingServiceInterface(com.google.api.ads.admanager.axis.v202108.CustomTargetingServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) CustomTargetingValuePage(com.google.api.ads.admanager.axis.v202108.CustomTargetingValuePage)

Example 48 with Statement

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

Example 49 with Statement

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

Example 50 with Statement

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

the class DeactivateLabels method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param labelId the ID of the 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 LabelService.
    LabelServiceInterface labelService = adManagerServices.get(session, LabelServiceInterface.class);
    // Create a statement to select a label.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", labelId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get labels by statement.
        LabelPage page = labelService.getLabelsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Label label : page.getResults()) {
                System.out.printf("%d) Label with ID %d will be deactivated.%n", i++, label.getId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of labels to be deactivated: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        com.google.api.ads.admanager.axis.v202108.DeactivateLabels action = new com.google.api.ads.admanager.axis.v202108.DeactivateLabels();
        // Perform action.
        UpdateResult result = labelService.performLabelAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of labels deactivated: %d%n", result.getNumChanges());
        } else {
            System.out.println("No labels were deactivated.");
        }
    }
}
Also used : Label(com.google.api.ads.admanager.axis.v202108.Label) LabelPage(com.google.api.ads.admanager.axis.v202108.LabelPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) LabelServiceInterface(com.google.api.ads.admanager.axis.v202108.LabelServiceInterface) UpdateResult(com.google.api.ads.admanager.axis.v202108.UpdateResult)

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)119 Test (org.junit.Test)61 UpdateResult (com.google.api.ads.admanager.axis.v202108.UpdateResult)18 Statement (com.google.api.ads.admanager.axis.v202105.Statement)16 Statement (com.google.api.ads.admanager.axis.v202108.Statement)16 Statement (com.google.api.ads.admanager.axis.v202111.Statement)16 Statement (com.google.api.ads.admanager.axis.v202202.Statement)13 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202108.CustomTargetingServiceInterface)8 InventoryServiceInterface (com.google.api.ads.admanager.axis.v202108.InventoryServiceInterface)8 AdUnit (com.google.api.ads.admanager.axis.v202108.AdUnit)7 AdUnitPage (com.google.api.ads.admanager.axis.v202108.AdUnitPage)7 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202108.PublisherQueryLanguageServiceInterface)7 ResultSet (com.google.api.ads.admanager.axis.v202108.ResultSet)7 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 CustomFieldServiceInterface (com.google.api.ads.admanager.axis.v202108.CustomFieldServiceInterface)5 Creative (com.google.api.ads.admanager.axis.v202108.Creative)4 CreativeServiceInterface (com.google.api.ads.admanager.axis.v202108.CreativeServiceInterface)4 Label (com.google.api.ads.admanager.axis.v202108.Label)4