Package com.google.api.adwords.v201309.cm

Examples of com.google.api.adwords.v201309.cm.AdGroupAdOperation


          AdGroupAd adGroupAd = new AdGroupAd();
          adGroupAd.setAd(ad);
          adGroupAd.setAdGroupId(adGroup.getId());

          adGroupAdService.mutate(new AdGroupAdOperation[] {new AdGroupAdOperation(Operator.ADD,
              "ADD", adGroupAd, null)});
        }

        numAds = generator.nextInt(10) + 1;
        for (int k = 0; k < numAds; k++) {
          ImageAd ad = new ImageAd();
          Image image = new Image();
          image.setData(DataUtils.getTestImage());
          image.setName("name.jpg");
          ad.setImage(image);
          ad.setDisplayUrl("http://google.com/");
          ad.setUrl("http://example.com");
          ad.setName("name.jpg");

          AdGroupAd adGroupAd = new AdGroupAd();
          adGroupAd.setAd(ad);
          adGroupAd.setAdGroupId(adGroup.getId());

          adGroupAdService.mutate(new AdGroupAdOperation[] {new AdGroupAdOperation(Operator.ADD,
              "ADD", adGroupAd, null)});
        }

        ArrayList<AdGroupCriterionOperation> criteriaOps =
            new ArrayList<AdGroupCriterionOperation>();
View Full Code Here


    AdGroupAd ad = new AdGroupAd();
    ad.setAdGroupId(adGroupId);
    ad.setAd(textAd);

    // Create operations.
    AdGroupAdOperation textAdGroupAdOperation = new AdGroupAdOperation();
    textAdGroupAdOperation.setOperand(ad);
    textAdGroupAdOperation.setOperator(Operator.ADD);
    AdGroupAdOperation[] operations = new AdGroupAdOperation[] {textAdGroupAdOperation};

    // Add ads.
    AdGroupAdReturnValue result = service.mutate(operations);
    AdGroupAd testAd = result.getValue()[0];
View Full Code Here

    adGroupAd.setAdGroupId(adGroupId);
    adGroupAd.setAd(ad);
    adGroupAd.setStatus(AdGroupAdStatus.PAUSED);

    // Create operations.
    AdGroupAdOperation operation = new AdGroupAdOperation();
    operation.setOperand(adGroupAd);
    operation.setOperator(Operator.SET);

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

    // Update ad.
    AdGroupAdReturnValue result = service.mutate(operations);
View Full Code Here

    adGroupAd.setAdGroupId(adGroupId);
    adGroupAd.setAd(ad);
    adGroupAd.setStatus(AdGroupAdStatus.PAUSED);

    // Create operations.
    AdGroupAdOperation operation = new AdGroupAdOperation();
    operation.setOperand(adGroupAd);
    operation.setOperator(Operator.REMOVE);

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

    // Remove ad.
    AdGroupAdReturnValue result = service.mutate(operations);
View Full Code Here

    AdGroupAd textAdGroupAd = new AdGroupAd();
    textAdGroupAd.setAdGroupId(adGroupId);
    textAdGroupAd.setAd(textAd);

    // Create operations.
    AdGroupAdOperation textAdGroupAdOperation = new AdGroupAdOperation();
    textAdGroupAdOperation.setOperand(textAdGroupAd);
    textAdGroupAdOperation.setOperator(Operator.ADD);
    AdGroupAdOperation[] operations = new AdGroupAdOperation[] {textAdGroupAdOperation};

    // Add new TextAd and return its ID.
    return adGroupAdService.mutate(operations).getValue()[0].getAd().getId();
  }
View Full Code Here

      AdGroupAd exemptableAdGroupAd = new AdGroupAd();
      exemptableAdGroupAd.setAdGroupId(adGroupId);
      exemptableAdGroupAd.setAd(exemptableTextAd);

      // Create operations.
      AdGroupAdOperation exemptableOperation = new AdGroupAdOperation();
      exemptableOperation.setOperand(exemptableAdGroupAd);
      exemptableOperation.setOperator(Operator.ADD);

      // Create text ad that violates an non-exemptable policy.
      TextAd nonExemptableTextAd = new TextAd();
      nonExemptableTextAd.setHeadline("Mars Cruise with too long of a headline.");
      nonExemptableTextAd.setDescription1("Visit the Red Planet in style.");
      nonExemptableTextAd.setDescription2("Low-gravity fun for everyone.");
      nonExemptableTextAd.setDisplayUrl("www.example.com");
      nonExemptableTextAd.setUrl("http://www.example.com/");

      // Create ad group ad.
      AdGroupAd nonExemptableAdGroupAd = new AdGroupAd();
      nonExemptableAdGroupAd.setAdGroupId(adGroupId);
      nonExemptableAdGroupAd.setAd(nonExemptableTextAd);

      // Create operations.
      AdGroupAdOperation nonExemptableOperation = new AdGroupAdOperation();
      nonExemptableOperation.setOperand(nonExemptableAdGroupAd);
      nonExemptableOperation.setOperator(Operator.ADD);

      AdGroupAdOperation[] operations =
          new AdGroupAdOperation[] {exemptableOperation, nonExemptableOperation};

      try {
        // Validate the ads.
        AdGroupAdReturnValue result = adGroupAdValidationService.mutate(operations);
      } catch (ApiException e) {
        Set<Integer> indicesToRemove = new HashSet<Integer>();
        for (ApiError error : e.getErrors()) {
          if (error instanceof PolicyViolationError) {
            PolicyViolationError policyVioloationError = (PolicyViolationError) error;
            Matcher matcher = operationIndexPattern.matcher(error.getFieldPath());
            if (matcher.matches()) {
              int operationIndex = Integer.parseInt(matcher.group(1));
              AdGroupAdOperation operation = operations[operationIndex];
              System.out.printf("Ad with headline \"%s\" violated %s policy \"%s\".\n",
                  ((TextAd) operation.getOperand().getAd()).getHeadline(), policyVioloationError
                      .getIsExemptable() ? "exemptable" : "non-exemptable", policyVioloationError
                      .getExternalPolicyName());
              if (policyVioloationError.getIsExemptable()) {
                // Add exemption request to the operation.
                System.out.printf(
                    "Adding exemption request for policy name \"%s\" on text \"%s\".\n",
                    policyVioloationError.getKey().getPolicyName(), policyVioloationError.getKey()
                        .getViolatingText());
                List<ExemptionRequest> exemptionRequests =
                    new ArrayList<ExemptionRequest>(Arrays
                        .asList(operation.getExemptionRequests() == null
                            ? new ExemptionRequest[] {} : operation.getExemptionRequests()));
                exemptionRequests.add(new ExemptionRequest(policyVioloationError.getKey()));
                operation
                    .setExemptionRequests(exemptionRequests.toArray(new ExemptionRequest[] {}));
              } else {
                // Remove non-exemptable operation.
                System.out.println("Removing non-exemptable operation at index " + operationIndex
                    + ".");
                indicesToRemove.add(operationIndex);
              }
            }
          } else {
            // Non-policy error returned.
            Matcher matcher = operationIndexPattern.matcher(error.getFieldPath());
            if (matcher.matches()) {
              int operationIndex = Integer.parseInt(matcher.group(1));
              AdGroupAdOperation operation = operations[operationIndex];
              System.out.printf("Ad with headline \"%s\" created non-policy error \"%s\".\n",
                  ((TextAd) operation.getOperand().getAd()).getHeadline(), error.getErrorString());
              System.out.println("Removing non-exemptable operation at index " + operationIndex
                  + ".");
              indicesToRemove.add(operationIndex);
            }
          }
View Full Code Here

    // Optional: Set the status.
    clickToDownloadAppAdGroupAd.setStatus(AdGroupAdStatus.PAUSED);

    // Create the operation.
    AdGroupAdOperation operation = new AdGroupAdOperation();
    operation.setOperator(Operator.ADD);
    operation.setOperand(clickToDownloadAppAdGroupAd);

    // Create the ads.
    AdGroupAdReturnValue result = adGroupAdService.mutate(new AdGroupAdOperation[] {operation});

    for (AdGroupAd adGroupAd : result.getValue()) {
View Full Code Here

      adGroupAd.setAdGroupId(adGroupId);
      adGroupAd.setAd(ad);
      adGroupAd.setStatus(AdGroupAdStatus.PAUSED);

      // Create operations.
      AdGroupAdOperation operation = new AdGroupAdOperation();
      operation.setOperand(adGroupAd);
      operation.setOperator(Operator.SET);

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

      // Update ad.
      AdGroupAdReturnValue result = adGroupAdService.mutate(operations);
View Full Code Here

      AdGroupAd templateAdGroupAd = new AdGroupAd();
      templateAdGroupAd.setAdGroupId(adGroupId);
      templateAdGroupAd.setAd(templateAd);

      // Create operations.
      AdGroupAdOperation textAdGroupAdOperation = new AdGroupAdOperation();
      textAdGroupAdOperation.setOperand(textAdGroupAd);
      textAdGroupAdOperation.setOperator(Operator.ADD);

      AdGroupAdOperation imageAdGroupAdOperation = new AdGroupAdOperation();
      imageAdGroupAdOperation.setOperand(imageAdGroupAd);
      imageAdGroupAdOperation.setOperator(Operator.ADD);

      AdGroupAdOperation templateAdGroupAdOperation = new AdGroupAdOperation();
      templateAdGroupAdOperation.setOperand(templateAdGroupAd);
      templateAdGroupAdOperation.setOperator(Operator.ADD);

      AdGroupAdOperation[] operations = new AdGroupAdOperation[] {textAdGroupAdOperation,
          imageAdGroupAdOperation, templateAdGroupAdOperation};

      // Add ads.
View Full Code Here

      AdGroupAd adGroupAd = new AdGroupAd();
      adGroupAd.setAdGroupId(adGroupId);
      adGroupAd.setAd(ad);

      // Create operations.
      AdGroupAdOperation operation = new AdGroupAdOperation();
      operation.setOperand(adGroupAd);
      operation.setOperator(Operator.REMOVE);

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

      // Delete ad.
      AdGroupAdReturnValue result = adGroupAdService.mutate(operations);
View Full Code Here

TOP

Related Classes of com.google.api.adwords.v201309.cm.AdGroupAdOperation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.