use of com.google.api.ads.adwords.axis.v201809.cm.CustomerNegativeCriterion 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());
}
}
Aggregations