Search in sources :

Example 51 with Statement

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

the class GetAllLabels 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 LabelService.
    LabelServiceInterface labelService = adManagerServices.get(session, LabelServiceInterface.class);
    // Create a statement to select all labels.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // 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 and name '%s' was found.%n", i++, label.getId(), label.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : 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) Label(com.google.api.ads.admanager.axis.v202108.Label)

Example 52 with Statement

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

the class GetActiveCreativeWrappers 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 {
    CreativeWrapperServiceInterface creativeWrapperService = adManagerServices.get(session, CreativeWrapperServiceInterface.class);
    // Create a statement to select creative wrappers.
    StatementBuilder statementBuilder = new StatementBuilder().where("status = :status").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("status", CreativeWrapperStatus.ACTIVE.toString());
    // Retrieve a small amount of creative wrappers at a time, paging through
    // until all creative wrappers have been retrieved.
    int totalResultSetSize = 0;
    do {
        CreativeWrapperPage page = creativeWrapperService.getCreativeWrappersByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            // Print out some information for each creative wrapper.
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (CreativeWrapper creativeWrapper : page.getResults()) {
                System.out.printf("%d) Creative wrapper with ID %d and label ID %d was found.%n", i++, creativeWrapper.getId(), creativeWrapper.getLabelId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : CreativeWrapper(com.google.api.ads.admanager.axis.v202108.CreativeWrapper) CreativeWrapperPage(com.google.api.ads.admanager.axis.v202108.CreativeWrapperPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) CreativeWrapperServiceInterface(com.google.api.ads.admanager.axis.v202108.CreativeWrapperServiceInterface)

Example 53 with Statement

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

the class UpdateCreativeWrappers method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param creativeWrapperId the ID of the creative wrapper 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 creativeWrapperId) throws RemoteException {
    // Get the CreativeWrapperService.
    CreativeWrapperServiceInterface creativeWrapperService = adManagerServices.get(session, CreativeWrapperServiceInterface.class);
    // Create a statement to only select a single creative wrapper by ID.
    StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", creativeWrapperId);
    // Get the creative wrapper.
    CreativeWrapperPage page = creativeWrapperService.getCreativeWrappersByStatement(statementBuilder.toStatement());
    CreativeWrapper creativeWrapper = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
    // Update the creative wrapper ordering.
    creativeWrapper.setOrdering(CreativeWrapperOrdering.OUTER);
    // Update the creative wrapper on the server.
    CreativeWrapper[] creativeWrappers = creativeWrapperService.updateCreativeWrappers(new CreativeWrapper[] { creativeWrapper });
    for (CreativeWrapper updatedCreativeWrapper : creativeWrappers) {
        System.out.printf("Creative wrapper with ID %d and wrapping order '%s' was updated.%n", updatedCreativeWrapper.getId(), updatedCreativeWrapper.getOrdering());
    }
}
Also used : CreativeWrapper(com.google.api.ads.admanager.axis.v202108.CreativeWrapper) CreativeWrapperPage(com.google.api.ads.admanager.axis.v202108.CreativeWrapperPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) CreativeWrapperServiceInterface(com.google.api.ads.admanager.axis.v202108.CreativeWrapperServiceInterface)

Example 54 with Statement

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

the class UpdateCustomFields method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param customFieldId the ID of the custom field 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 customFieldId) throws RemoteException {
    // Get the CustomFieldService.
    CustomFieldServiceInterface customFieldService = adManagerServices.get(session, CustomFieldServiceInterface.class);
    // Create a statement to only select a single custom field by ID.
    StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", customFieldId);
    // Get the custom field.
    CustomFieldPage page = customFieldService.getCustomFieldsByStatement(statementBuilder.toStatement());
    CustomField customField = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
    // Update the custom field description.
    customField.setDescription("New custom field description");
    // Update the custom field on the server.
    CustomField[] customFields = customFieldService.updateCustomFields(new CustomField[] { customField });
    for (CustomField updatedCustomField : customFields) {
        System.out.printf("Custom field with ID %d and name '%s' was updated.%n", updatedCustomField.getId(), updatedCustomField.getName());
    }
}
Also used : CustomFieldPage(com.google.api.ads.admanager.axis.v202108.CustomFieldPage) CustomFieldServiceInterface(com.google.api.ads.admanager.axis.v202108.CustomFieldServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) CustomField(com.google.api.ads.admanager.axis.v202108.CustomField)

Example 55 with Statement

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

the class GetAdUnitHierarchy method getAllAdUnits.

/**
 * Get all ad units.
 */
private static List<AdUnit> getAllAdUnits(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    List<AdUnit> adUnits = new ArrayList<>();
    // Get the InventoryService.
    InventoryServiceInterface inventoryService = adManagerServices.get(session, InventoryServiceInterface.class);
    // Create a statement to select all ad units.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get ad units by statement.
        AdUnitPage page = inventoryService.getAdUnitsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            Collections.addAll(adUnits, page.getResults());
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    return adUnits;
}
Also used : AdUnitPage(com.google.api.ads.admanager.axis.v202108.AdUnitPage) AdUnit(com.google.api.ads.admanager.axis.v202108.AdUnit) InventoryServiceInterface(com.google.api.ads.admanager.axis.v202108.InventoryServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) ArrayList(java.util.ArrayList)

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