Search in sources :

Example 11 with LabelServiceInterface

use of com.google.api.ads.admanager.axis.v202111.LabelServiceInterface 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.v202108.LabelServiceInterface) Label(com.google.api.ads.admanager.axis.v202108.Label)

Example 12 with LabelServiceInterface

use of com.google.api.ads.admanager.axis.v202111.LabelServiceInterface 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.v202111.LabelServiceInterface) Label(com.google.api.ads.admanager.axis.v202111.Label)

Example 13 with LabelServiceInterface

use of com.google.api.ads.admanager.axis.v202111.LabelServiceInterface 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.v202111.LabelPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) LabelServiceInterface(com.google.api.ads.admanager.axis.v202111.LabelServiceInterface) Label(com.google.api.ads.admanager.axis.v202111.Label)

Example 14 with LabelServiceInterface

use of com.google.api.ads.admanager.axis.v202111.LabelServiceInterface 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 15 with LabelServiceInterface

use of com.google.api.ads.admanager.axis.v202111.LabelServiceInterface 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

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 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)4 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)4 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)4 LabelPage (com.google.api.ads.admanager.axis.v202108.LabelPage)4 LabelPage (com.google.api.ads.admanager.axis.v202111.LabelPage)4 LabelPage (com.google.api.ads.admanager.axis.v202202.LabelPage)4 Random (java.util.Random)3 UpdateResult (com.google.api.ads.admanager.axis.v202108.UpdateResult)1 UpdateResult (com.google.api.ads.admanager.axis.v202111.UpdateResult)1 UpdateResult (com.google.api.ads.admanager.axis.v202202.UpdateResult)1