* @param adGroupId the id of the parent ad group
* @return the id of the created criterion
*/
public long createKeyword(long adGroupId) throws Exception {
// Get the AdGroupCriterionService.
AdGroupCriterionServiceInterface adGroupCriterionService =
user.getService(AdWordsService.V201008.ADGROUP_CRITERION_SERVICE);
// Create keyword.
Keyword keyword = new Keyword();
keyword.setText("mars cruise");
keyword.setMatchType(KeywordMatchType.BROAD);
// Create biddable ad group criterion.
BiddableAdGroupCriterion keywordBiddableAdGroupCriterion = new BiddableAdGroupCriterion();
keywordBiddableAdGroupCriterion.setAdGroupId(adGroupId);
keywordBiddableAdGroupCriterion.setCriterion(keyword);
// Create placement.
Placement placement = new Placement();
placement.setUrl("http://mars.google.com");
// Create biddable ad group criterion for placement.
BiddableAdGroupCriterion placementBiddableAdGroupCriterion = new BiddableAdGroupCriterion();
placementBiddableAdGroupCriterion.setAdGroupId(adGroupId);
placementBiddableAdGroupCriterion.setCriterion(placement);
// Create operations.
AdGroupCriterionOperation keywordAdGroupCriterionOperation = new AdGroupCriterionOperation();
keywordAdGroupCriterionOperation.setOperand(keywordBiddableAdGroupCriterion);
keywordAdGroupCriterionOperation.setOperator(Operator.ADD);
AdGroupCriterionOperation placementAdGroupCriterionOperation = new AdGroupCriterionOperation();
placementAdGroupCriterionOperation.setOperand(placementBiddableAdGroupCriterion);
placementAdGroupCriterionOperation.setOperator(Operator.ADD);
AdGroupCriterionOperation[] operations = new AdGroupCriterionOperation[] {
keywordAdGroupCriterionOperation, placementAdGroupCriterionOperation};
// Add ad group criteria and return Criterion ID.
return adGroupCriterionService.mutate(operations).getValue()[0].getCriterion().getId();
}