Search in sources :

Example 31 with Label

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

the class GetAllCreativeWrappers 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 CreativeWrapperService.
    CreativeWrapperServiceInterface creativeWrapperService = adManagerServices.get(session, CreativeWrapperServiceInterface.class);
    // Create a statement to select all creative wrappers.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get creative wrappers by statement.
        CreativeWrapperPage page = creativeWrapperService.getCreativeWrappersByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (CreativeWrapper creativeWrapper : page.getResults()) {
                System.out.printf("%d) Creative wrapper with ID %d applying to 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.v202111.CreativeWrapper) CreativeWrapperPage(com.google.api.ads.admanager.axis.v202111.CreativeWrapperPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) CreativeWrapperServiceInterface(com.google.api.ads.admanager.axis.v202111.CreativeWrapperServiceInterface)

Example 32 with Label

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

the class CreateCreativeWrappers method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param labelId the ID of the label that can be associated with creative wrappers.
 * @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 CreativeWrapperService.
    CreativeWrapperServiceInterface creativeWrapperService = adManagerServices.get(session, CreativeWrapperServiceInterface.class);
    // Create a creative wrapper.
    CreativeWrapper innerCreativeWrapper = new CreativeWrapper();
    // A label can only be associated with one creative wrapper.
    innerCreativeWrapper.setLabelId(labelId);
    innerCreativeWrapper.setOrdering(CreativeWrapperOrdering.INNER);
    innerCreativeWrapper.setHtmlHeader("<b>My creative wrapper header</b>");
    innerCreativeWrapper.setHtmlFooter("<b>My creative wrapper footer</b>");
    // Create the creative wrapper on the server.
    CreativeWrapper[] creativeWrappers = creativeWrapperService.createCreativeWrappers(new CreativeWrapper[] { innerCreativeWrapper });
    for (CreativeWrapper createdCreativeWrapper : creativeWrappers) {
        System.out.printf("Creative wrapper with ID %d applying to label ID %d was created.%n", createdCreativeWrapper.getId(), createdCreativeWrapper.getLabelId());
    }
}
Also used : CreativeWrapper(com.google.api.ads.admanager.axis.v202111.CreativeWrapper) CreativeWrapperServiceInterface(com.google.api.ads.admanager.axis.v202111.CreativeWrapperServiceInterface)

Example 33 with Label

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

the class DeactivateCreativeWrappersForLabel method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param labelId the ID of the creative wrapper 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 CreativeWrapperService.
    CreativeWrapperServiceInterface creativeWrapperService = adManagerServices.get(session, CreativeWrapperServiceInterface.class);
    // Create a statement to select the active creative wrappers for the
    // given label.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE status = :status AND labelId = :labelId").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("status", CreativeWrapperStatus.ACTIVE.toString()).withBindVariableValue("labelId", labelId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get creative wrappers by statement.
        CreativeWrapperPage page = creativeWrapperService.getCreativeWrappersByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (CreativeWrapper creativeWrapper : page.getResults()) {
                System.out.printf("%d) Creative wrapper with ID %d applying to label ID" + " %d will be deactivated.%n", i++, creativeWrapper.getId(), creativeWrapper.getLabelId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of creative wrappers to be deactivated: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        DeactivateCreativeWrappers action = new DeactivateCreativeWrappers();
        // Perform action.
        UpdateResult result = creativeWrapperService.performCreativeWrapperAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of creative wrappers deactivated: %d%n", result.getNumChanges());
        } else {
            System.out.println("No creative wrappers were deactivated.");
        }
    }
}
Also used : CreativeWrapper(com.google.api.ads.admanager.axis.v202111.CreativeWrapper) CreativeWrapperPage(com.google.api.ads.admanager.axis.v202111.CreativeWrapperPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) DeactivateCreativeWrappers(com.google.api.ads.admanager.axis.v202111.DeactivateCreativeWrappers) CreativeWrapperServiceInterface(com.google.api.ads.admanager.axis.v202111.CreativeWrapperServiceInterface) UpdateResult(com.google.api.ads.admanager.axis.v202111.UpdateResult)

Example 34 with Label

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

the class CreateLabels 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 competitive exclusion label.
    Label competitiveExclusionLabel = new Label();
    competitiveExclusionLabel.setName("Car company label #" + new Random().nextInt(Integer.MAX_VALUE));
    competitiveExclusionLabel.setTypes(new LabelType[] { LabelType.COMPETITIVE_EXCLUSION });
    // Create an ad unit frequency cap label.
    Label adUnitFrequencyCapLabel = new Label();
    adUnitFrequencyCapLabel.setName("Don't run too often label #" + new Random().nextInt(Integer.MAX_VALUE));
    adUnitFrequencyCapLabel.setTypes(new LabelType[] { LabelType.AD_UNIT_FREQUENCY_CAP });
    // Create the labels on the server.
    Label[] labels = labelService.createLabels(new Label[] { competitiveExclusionLabel, adUnitFrequencyCapLabel });
    for (Label createdLabel : labels) {
        System.out.printf("A label with ID %d and name '%s' was created.%n", createdLabel.getId(), createdLabel.getName());
    }
}
Also used : Random(java.util.Random) LabelServiceInterface(com.google.api.ads.admanager.axis.v202202.LabelServiceInterface) Label(com.google.api.ads.admanager.axis.v202202.Label)

Example 35 with Label

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

the class UpdateLabels method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param labelId the ID of the label 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 labelId) throws RemoteException {
    // Get the LabelService.
    LabelServiceInterface labelService = adManagerServices.get(session, LabelServiceInterface.class);
    // Create a statement to only select a single label by ID.
    StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", labelId);
    // Get the label.
    LabelPage page = labelService.getLabelsByStatement(statementBuilder.toStatement());
    Label label = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
    // Update the label description.
    label.setDescription("New label description");
    // Update the label on the server.
    Label[] labels = labelService.updateLabels(new Label[] { label });
    for (Label updatedLabel : labels) {
        System.out.printf("Label with ID %d and name '%s' was updated.%n", updatedLabel.getId(), updatedLabel.getName());
    }
}
Also used : LabelPage(com.google.api.ads.admanager.axis.v202202.LabelPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) LabelServiceInterface(com.google.api.ads.admanager.axis.v202202.LabelServiceInterface) Label(com.google.api.ads.admanager.axis.v202202.Label)

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)7 Label (org.apache.xbean.asm9.Label)7 Label (com.google.api.ads.admanager.axis.v202108.Label)5 LabelServiceInterface (com.google.api.ads.admanager.axis.v202108.LabelServiceInterface)5 Label (com.google.api.ads.admanager.axis.v202111.Label)5 LabelServiceInterface (com.google.api.ads.admanager.axis.v202111.LabelServiceInterface)5 Label (com.google.api.ads.admanager.axis.v202202.Label)5 LabelServiceInterface (com.google.api.ads.admanager.axis.v202202.LabelServiceInterface)5 MethodVisitor (org.apache.xbean.asm9.MethodVisitor)5 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)4 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)4 LabelPage (com.google.api.ads.admanager.axis.v202108.LabelPage)4 CreativeWrapper (com.google.api.ads.admanager.axis.v202111.CreativeWrapper)4 CreativeWrapperServiceInterface (com.google.api.ads.admanager.axis.v202111.CreativeWrapperServiceInterface)4 LabelPage (com.google.api.ads.admanager.axis.v202111.LabelPage)4 LabelPage (com.google.api.ads.admanager.axis.v202202.LabelPage)4 CreativeWrapperPage (com.google.api.ads.admanager.axis.v202111.CreativeWrapperPage)3 Random (java.util.Random)3 net.sf.cglib.asm.$Label (net.sf.cglib.asm.$Label)3 UpdateResult (com.google.api.ads.admanager.axis.v202111.UpdateResult)2