1

我是 Google AdWords API 的新手。Google AdWords API 的UpdateKeyword 类中没有提到Keyword,它只用于使用criteriaId 更新MaxCPC。通常 Google AdWords API 非常简单,但我不知道如何更新关键字属性。如何更新关键字、KeywordmMatchType 和 maxCPC?

  public static void runExample(
      AdWordsServicesInterface adWordsServices,
      AdWordsSession session,
      Long adGroupId,
      Long keywordId)
      throws RemoteException {
    // Get the AdGroupCriterionService.
    AdGroupCriterionServiceInterface adGroupCriterionService =
        adWordsServices.get(session, AdGroupCriterionServiceInterface.class);

    // Create ad group criterion with updated bid.
    Criterion criterion = new Criterion();
    criterion.setId(keywordId);

    BiddableAdGroupCriterion biddableAdGroupCriterion = new BiddableAdGroupCriterion();
    biddableAdGroupCriterion.setAdGroupId(adGroupId);
    biddableAdGroupCriterion.setCriterion(criterion);

    // Create bids.
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    CpcBid bid = new CpcBid();
    bid.setBid(new Money(null, 10000000L));
    biddingStrategyConfiguration.setBids(new Bids[] {bid});
    biddableAdGroupCriterion.setBiddingStrategyConfiguration(biddingStrategyConfiguration);

    // Create operations.
    AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
    operation.setOperand(biddableAdGroupCriterion);
    operation.setOperator(Operator.SET);

    AdGroupCriterionOperation[] operations = new AdGroupCriterionOperation[] {operation};

    // Update ad group criteria.
    AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(operations);

    // Display ad group criteria.
    for (AdGroupCriterion adGroupCriterionResult : result.getValue()) {
      if (adGroupCriterionResult instanceof BiddableAdGroupCriterion) {
        biddableAdGroupCriterion = (BiddableAdGroupCriterion) adGroupCriterionResult;
        CpcBid criterionCpcBid = null;
        // Find the criterion-level CpcBid among the keyword's bids.
        for (Bids bids : biddableAdGroupCriterion.getBiddingStrategyConfiguration().getBids()) {
          if (bids instanceof CpcBid) {
            CpcBid cpcBid = (CpcBid) bids;
            if (BidSource.CRITERION.equals(cpcBid.getCpcBidSource())) {
              criterionCpcBid = cpcBid;
            }
          }
        }

        System.out.printf(
            "Ad group criterion with ad group ID %d, criterion ID %d, type "
                + "'%s', and bid %d was updated.%n",
            biddableAdGroupCriterion.getAdGroupId(),
            biddableAdGroupCriterion.getCriterion().getId(),
            biddableAdGroupCriterion.getCriterion().getCriterionType(),
            criterionCpcBid.getBid().getMicroAmount());
      }
    }
  }
}
4

0 回答 0