public void Run(AdWordsUser user, long adGroupId, long keywordId)
{
// Get the AdGroupCriterionService.
AdGroupCriterionService adGroupCriterionService =
(AdGroupCriterionService) user.GetService(AdWordsService.v201306.AdGroupCriterionService);
// Since we are not updating any keyword-specific fields, it is enough to
// create a criterion object.
Criterion criterion = new Criterion();
criterion.id = keywordId;
// Create ad group criterion.
BiddableAdGroupCriterion biddableAdGroupCriterion = new BiddableAdGroupCriterion();
biddableAdGroupCriterion.adGroupId = adGroupId;
biddableAdGroupCriterion.criterion = criterion;
// Create the bids.
BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();
CpcBid cpcBid = new CpcBid();
cpcBid.bid = new Money();
cpcBid.bid.microAmount = 1000000;
biddingConfig.bids = new Bids[] {cpcBid};
biddableAdGroupCriterion.biddingStrategyConfiguration = biddingConfig;
// Create the operation.
AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
operation.@operator = Operator.SET;
operation.operand = biddableAdGroupCriterion;
try {
// Update the keyword.
AdGroupCriterionReturnValue retVal =
adGroupCriterionService.mutate(new AdGroupCriterionOperation[] {operation});
// Display the results.
if (retVal != null && retVal.value != null && retVal.value.Length > 0) {
AdGroupCriterion adGroupCriterion = retVal.value[0];
long bidAmount = 0;
foreach (Bids bids in (adGroupCriterion as BiddableAdGroupCriterion).
biddingStrategyConfiguration.bids) {
if (bids is CpcBid) {
bidAmount = (bids as CpcBid).bid.microAmount;
break;
}
}
Console.WriteLine("Keyword with ad group id = '{0}', id = '{1}' was updated with " +
"bid amount = '{2}' micros.", adGroupCriterion.adGroupId,
adGroupCriterion.criterion.id, bidAmount);
} else {
Console.WriteLine("No keyword was updated.");
}
} catch (Exception ex) {
throw new System.ApplicationException("Failed to update keyword.", ex);
}
}