Search in sources :

Example 1 with CustomerNegativeCriterionServiceInterface

use of com.google.api.ads.adwords.axis.v201809.cm.CustomerNegativeCriterionServiceInterface in project googleads-java-lib by googleads.

the class AddCustomerNegativeCriteria method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices 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(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
    // Get the CustomerNegativeCriterionService.
    CustomerNegativeCriterionServiceInterface customerNegativeCriterionService = adWordsServices.get(session, CustomerNegativeCriterionServiceInterface.class);
    List<Criterion> criteria = new ArrayList<>();
    // Exclude tragedy & conflict content.
    ContentLabel tragedyContentLabel = new ContentLabel();
    tragedyContentLabel.setContentLabelType(ContentLabelType.TRAGEDY);
    criteria.add(tragedyContentLabel);
    // Exclude a specific placement.
    Placement placement = new Placement();
    placement.setUrl("http://www.example.com");
    criteria.add(placement);
    // Additional criteria types are available for this service. See the types listed
    // under Criterion here:
    // https://developers.google.com/adwords/api/docs/reference/latest/CustomerNegativeCriterionService.Criterion
    // Create operations to add each of the criteria above.
    List<CustomerNegativeCriterionOperation> operations = new ArrayList<>();
    for (Criterion criterion : criteria) {
        CustomerNegativeCriterion negativeCriterion = new CustomerNegativeCriterion();
        negativeCriterion.setCriterion(criterion);
        CustomerNegativeCriterionOperation operation = new CustomerNegativeCriterionOperation();
        operation.setOperator(Operator.ADD);
        operation.setOperand(negativeCriterion);
        operations.add(operation);
    }
    // Send the request to add the criteria.
    CustomerNegativeCriterionReturnValue result = customerNegativeCriterionService.mutate(operations.toArray(new CustomerNegativeCriterionOperation[operations.size()]));
    // Display the results.
    for (CustomerNegativeCriterion negativeCriterion : result.getValue()) {
        System.out.printf("Customer negative criterion with criterion ID %d and type '%s' was added.%n", negativeCriterion.getCriterion().getId(), negativeCriterion.getCriterion().getCriterionType());
    }
}
Also used : ContentLabel(com.google.api.ads.adwords.axis.v201809.cm.ContentLabel) CustomerNegativeCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.CustomerNegativeCriterionOperation) CustomerNegativeCriterion(com.google.api.ads.adwords.axis.v201809.cm.CustomerNegativeCriterion) Criterion(com.google.api.ads.adwords.axis.v201809.cm.Criterion) Placement(com.google.api.ads.adwords.axis.v201809.cm.Placement) CustomerNegativeCriterion(com.google.api.ads.adwords.axis.v201809.cm.CustomerNegativeCriterion) CustomerNegativeCriterionReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CustomerNegativeCriterionReturnValue) ArrayList(java.util.ArrayList) CustomerNegativeCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CustomerNegativeCriterionServiceInterface)

Aggregations

ContentLabel (com.google.api.ads.adwords.axis.v201809.cm.ContentLabel)1 Criterion (com.google.api.ads.adwords.axis.v201809.cm.Criterion)1 CustomerNegativeCriterion (com.google.api.ads.adwords.axis.v201809.cm.CustomerNegativeCriterion)1 CustomerNegativeCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.CustomerNegativeCriterionOperation)1 CustomerNegativeCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CustomerNegativeCriterionReturnValue)1 CustomerNegativeCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CustomerNegativeCriterionServiceInterface)1 Placement (com.google.api.ads.adwords.axis.v201809.cm.Placement)1 ArrayList (java.util.ArrayList)1