Search in sources :

Example 91 with Statement

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

Example 92 with Statement

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

the class GetAllCreativeSets 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 CreativeSetService.
    CreativeSetServiceInterface creativeSetService = adManagerServices.get(session, CreativeSetServiceInterface.class);
    // Create a statement to get all creativeSets.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get creative sets by statement.
        CreativeSetPage page = creativeSetService.getCreativeSetsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (CreativeSet creativeSet : page.getResults()) {
                System.out.printf("%d) Creative set with ID %d and name '%s' was found.%n", i++, creativeSet.getId(), creativeSet.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) CreativeSetPage(com.google.api.ads.admanager.axis.v202108.CreativeSetPage) CreativeSet(com.google.api.ads.admanager.axis.v202108.CreativeSet) CreativeSetServiceInterface(com.google.api.ads.admanager.axis.v202108.CreativeSetServiceInterface)

Example 93 with Statement

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

the class GetAllLicas 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 LineItemCreativeAssociationService.
    LineItemCreativeAssociationServiceInterface licaService = adManagerServices.get(session, LineItemCreativeAssociationServiceInterface.class);
    // Create a statement to get all LICAs.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("lineItemId ASC, creativeId ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get LICAs by statement.
        LineItemCreativeAssociationPage page = licaService.getLineItemCreativeAssociationsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (LineItemCreativeAssociation lica : page.getResults()) {
                if (lica.getCreativeSetId() != null) {
                    System.out.printf("%d) LICA with line item ID %d and creative set ID %d was found.%n", i++, lica.getLineItemId(), lica.getCreativeSetId());
                } else {
                    System.out.printf("%d) LICA with line item ID %d and creative ID %d was found.%n", i++, lica.getLineItemId(), lica.getCreativeId());
                }
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : LineItemCreativeAssociation(com.google.api.ads.admanager.axis.v202108.LineItemCreativeAssociation) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) LineItemCreativeAssociationPage(com.google.api.ads.admanager.axis.v202108.LineItemCreativeAssociationPage) LineItemCreativeAssociationServiceInterface(com.google.api.ads.admanager.axis.v202108.LineItemCreativeAssociationServiceInterface)

Example 94 with Statement

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

the class PushCreativeToDevices method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param lineItemId the ID of the line item to push to a device.
 * @param creativeId the ID of the creative
 *       to push to a device.
 * @param linkedDeviceId the ID of the linked device to push the LICA to.
 * @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 lineItemId, long creativeId, long linkedDeviceId) throws RemoteException {
    // Get the LineItemCreativeAssociationService.
    LineItemCreativeAssociationServiceInterface licaService = adManagerServices.get(session, LineItemCreativeAssociationServiceInterface.class);
    // Create a statement to select a single linked device.
    // Linked devices can be read from the linked_device PQL table.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :linkedDeviceId").withBindVariableValue("linkedDeviceId", linkedDeviceId);
    CreativePushOptions options = new CreativePushOptions();
    options.setLineItemId(lineItemId);
    options.setCreativeId(creativeId);
    UpdateResult updateResult = licaService.pushCreativeToDevices(statementBuilder.toStatement(), options);
    System.out.printf("Pushed creative to %d devices%n", updateResult.getNumChanges());
}
Also used : CreativePushOptions(com.google.api.ads.admanager.axis.v202108.CreativePushOptions) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) LineItemCreativeAssociationServiceInterface(com.google.api.ads.admanager.axis.v202108.LineItemCreativeAssociationServiceInterface) UpdateResult(com.google.api.ads.admanager.axis.v202108.UpdateResult)

Example 95 with Statement

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

the class UpdateCreativeSets method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param creativeSetId the ID of the creative set to update.
 * @param companionCreativeId the ID of the companion creative to add to the creative set.
 * @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 creativeSetId, long companionCreativeId) throws RemoteException {
    // Get the CreativeSetService.
    CreativeSetServiceInterface creativeSetService = adManagerServices.get(session, CreativeSetServiceInterface.class);
    // Create a statement to only select a single creative set by ID.
    StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", creativeSetId);
    // Get the creative set.
    CreativeSetPage page = creativeSetService.getCreativeSetsByStatement(statementBuilder.toStatement());
    CreativeSet creativeSet = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
    // Add the companion creative to the creative set.
    creativeSet.setCompanionCreativeIds(Longs.concat(creativeSet.getCompanionCreativeIds(), new long[] { companionCreativeId }));
    // Update the creative set on the server.
    CreativeSet updatedCreativeSet = creativeSetService.updateCreativeSet(creativeSet);
    System.out.printf("A creative set with ID %d, master creative ID %d, " + "and companion creative IDs [%s] was updated.", updatedCreativeSet.getId(), updatedCreativeSet.getMasterCreativeId(), Longs.join(",", updatedCreativeSet.getCompanionCreativeIds()));
}
Also used : StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) CreativeSetPage(com.google.api.ads.admanager.axis.v202108.CreativeSetPage) CreativeSet(com.google.api.ads.admanager.axis.v202108.CreativeSet) CreativeSetServiceInterface(com.google.api.ads.admanager.axis.v202108.CreativeSetServiceInterface)

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