Search in sources :

Example 56 with Statement

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

the class GetCustomFieldsForLineItems 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 {
    CustomFieldServiceInterface customFieldService = adManagerServices.get(session, CustomFieldServiceInterface.class);
    // Create a statement to select custom fields.
    StatementBuilder statementBuilder = new StatementBuilder().where("entityType = :entityType").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("entityType", CustomFieldEntityType.LINE_ITEM.toString());
    // Retrieve a small amount of custom fields at a time, paging through
    // until all custom fields have been retrieved.
    int totalResultSetSize = 0;
    do {
        CustomFieldPage page = customFieldService.getCustomFieldsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            // Print out some information for each custom field.
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (CustomField customField : page.getResults()) {
                System.out.printf("%d) Custom field with ID %d and name '%s' was found.%n", i++, customField.getId(), customField.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : CustomFieldPage(com.google.api.ads.admanager.axis.v202202.CustomFieldPage) CustomFieldServiceInterface(com.google.api.ads.admanager.axis.v202202.CustomFieldServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) CustomField(com.google.api.ads.admanager.axis.v202202.CustomField)

Example 57 with Statement

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

the class DeleteCustomTargetingKeys method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param customTargetingKeyId the ID of the custom targeting key.
 * @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 select a custom targeting key.
    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) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (CustomTargetingKey customTargetingKey : page.getResults()) {
                System.out.printf("%d) Custom targeting key with ID %d" + " will be deleted.%n", i++, customTargetingKey.getId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of custom targeting keys 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.v202202.DeleteCustomTargetingKeys action = new com.google.api.ads.admanager.axis.v202202.DeleteCustomTargetingKeys();
        // Perform action.
        UpdateResult result = customTargetingService.performCustomTargetingKeyAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of custom targeting keys deleted: %d%n", result.getNumChanges());
        } else {
            System.out.println("No custom targeting keys were deleted.");
        }
    }
}
Also used : CustomTargetingServiceInterface(com.google.api.ads.admanager.axis.v202202.CustomTargetingServiceInterface) CustomTargetingKey(com.google.api.ads.admanager.axis.v202202.CustomTargetingKey) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) CustomTargetingKeyPage(com.google.api.ads.admanager.axis.v202202.CustomTargetingKeyPage) UpdateResult(com.google.api.ads.admanager.axis.v202202.UpdateResult)

Example 58 with Statement

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

the class GetAllCustomTargetingKeysAndValues 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);
    // Get all custom targeting keys.
    List<Long> customTargetingKeyIds = getAllCustomTargetingKeyIds(adManagerServices, session);
    // Create a statement to get all custom targeting values for a custom
    // targeting key.
    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);
        // Default for total result set size and offset.
        int totalResultSetSize = 0;
        statementBuilder.offset(0);
        do {
            // Get custom targeting values by statement.
            CustomTargetingValuePage page = customTargetingService.getCustomTargetingValuesByStatement(statementBuilder.toStatement());
            if (page.getResults() != null) {
                totalResultSetSize = page.getTotalResultSetSize();
                for (CustomTargetingValue customTargetingValue : page.getResults()) {
                    System.out.printf("%d) Custom targeting value with ID %d, belonging to key " + "with ID %d, name '%s' and display name '%s' was found.%n", totalResultsCounter++, customTargetingValue.getId(), customTargetingValue.getCustomTargetingKeyId(), customTargetingValue.getName(), customTargetingValue.getDisplayName());
                }
            }
            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.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 59 with Statement

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

the class GetAllCustomTargetingKeysAndValues method getAllCustomTargetingKeyIds.

/**
 * Gets all custom targeting key IDs.
 */
private static List<Long> getAllCustomTargetingKeyIds(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    List<Long> customTargetingKeyIds = new ArrayList<>();
    // Get the CustomTargetingService.
    CustomTargetingServiceInterface customTargetingService = adManagerServices.get(session, CustomTargetingServiceInterface.class);
    // Create a statement to get all custom targeting keys.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // 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.v202202.CustomTargetingServiceInterface) CustomTargetingKey(com.google.api.ads.admanager.axis.v202202.CustomTargetingKey) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) ArrayList(java.util.ArrayList) CustomTargetingKeyPage(com.google.api.ads.admanager.axis.v202202.CustomTargetingKeyPage)

Example 60 with Statement

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

the class UpdateActivities method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param activityId the ID of the activity 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 activityId) throws RemoteException {
    // Get the ActivityService.
    ActivityServiceInterface activityService = adManagerServices.get(session, ActivityServiceInterface.class);
    // Create a statement to only select a single activity by ID.
    StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", activityId);
    // Get the activity.
    ActivityPage page = activityService.getActivitiesByStatement(statementBuilder.toStatement());
    // Get the activity.
    Activity activity = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
    // Update the expected URL.
    activity.setExpectedURL("http://google.com");
    // Update the activity on the server.
    Activity[] activities = activityService.updateActivities(new Activity[] { activity });
    for (Activity updatedActivity : activities) {
        System.out.printf("Activity with ID %d and name '%s' was updated.%n", updatedActivity.getId(), updatedActivity.getName());
    }
}
Also used : ActivityPage(com.google.api.ads.admanager.axis.v202202.ActivityPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) ActivityServiceInterface(com.google.api.ads.admanager.axis.v202202.ActivityServiceInterface) Activity(com.google.api.ads.admanager.axis.v202202.Activity)

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)119 Test (org.junit.Test)61 UpdateResult (com.google.api.ads.admanager.axis.v202202.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)16 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202202.CustomTargetingServiceInterface)8 InventoryServiceInterface (com.google.api.ads.admanager.axis.v202202.InventoryServiceInterface)8 AdUnit (com.google.api.ads.admanager.axis.v202202.AdUnit)7 AdUnitPage (com.google.api.ads.admanager.axis.v202202.AdUnitPage)7 LineItem (com.google.api.ads.admanager.axis.v202202.LineItem)6 LineItemPage (com.google.api.ads.admanager.axis.v202202.LineItemPage)6 LineItemServiceInterface (com.google.api.ads.admanager.axis.v202202.LineItemServiceInterface)6 LineItemCreativeAssociationServiceInterface (com.google.api.ads.admanager.axis.v202202.LineItemCreativeAssociationServiceInterface)5 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202202.PublisherQueryLanguageServiceInterface)5 ResultSet (com.google.api.ads.admanager.axis.v202202.ResultSet)5 CustomTargetingValue (com.google.api.ads.admanager.axis.v202202.CustomTargetingValue)4 CustomTargetingValuePage (com.google.api.ads.admanager.axis.v202202.CustomTargetingValuePage)4 String_ValueMapEntry (com.google.api.ads.admanager.axis.v202202.String_ValueMapEntry)4