Package com.google.api.adwords.v201306.cm

Examples of com.google.api.adwords.v201306.cm.AuthenticationError


      // Create ad extension override.
      AdExtensionOverride adExtensionOverride = new AdExtensionOverride();
      adExtensionOverride.setAdId(adId);

      // Create ad extension using existing id.
      AdExtension adExtension = new AdExtension();
      adExtension.setId(campaignAdExtensionId);
      adExtensionOverride.setAdExtension(adExtension);

      // Create operations.
      AdExtensionOverrideOperation operation = new AdExtensionOverrideOperation();
      operation.setOperand(adExtensionOverride);
View Full Code Here


      long adId = Long.parseLong("INSERT_AD_ID_HERE");
      long campaignAdExtensionId = Long.parseLong("INSERT_CAMPAIGN_AD_EXTENSION_ID_HERE");

      // Create ad extension override.
      AdExtensionOverride adExtensionOverride = new AdExtensionOverride();
      adExtensionOverride.setAdId(adId);

      // Create ad extension using existing id.
      AdExtension adExtension = new AdExtension();
      adExtension.setId(campaignAdExtensionId);
      adExtensionOverride.setAdExtension(adExtension);

      // Create operations.
      AdExtensionOverrideOperation operation = new AdExtensionOverrideOperation();
      operation.setOperand(adExtensionOverride);
      operation.setOperator(Operator.ADD);
View Full Code Here

      AdExtension adExtension = new AdExtension();
      adExtension.setId(campaignAdExtensionId);
      adExtensionOverride.setAdExtension(adExtension);

      // Create operations.
      AdExtensionOverrideOperation operation = new AdExtensionOverrideOperation();
      operation.setOperand(adExtensionOverride);
      operation.setOperator(Operator.ADD);

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

      // Add ad extension override.
      AdExtensionOverrideReturnValue result = adExtensionOverrideService.mutate(operations);
View Full Code Here

      operation.setOperator(Operator.ADD);

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

      // Add ad extension override.
      AdExtensionOverrideReturnValue result = adExtensionOverrideService.mutate(operations);

      // Display ad extension overrides.
      if (result != null && result.getValue() != null) {
        for (AdExtensionOverride adExtensionOverrideResult : result.getValue()) {
          System.out.println("Ad extension override with ad id \""
              + adExtensionOverrideResult.getAdId() + "\" and ad extension id \""
              + adExtensionOverrideResult.getAdExtension().getId() + "\" was added.");
        }
      } else {
View Full Code Here

      // Get AdWordsUser from "~/adwords.properties".
      AdWordsUser user = new AdWordsUser();

      // Get the AdExtensionOverrideService.
      AdExtensionOverrideServiceInterface adExtensionOverrideService =
          user.getService(AdWordsService.V201306.AD_EXTENSION_OVERRIDE_SERVICE);

      long adId = Long.parseLong("INSERT_AD_ID_HERE");
      long campaignAdExtensionId = Long.parseLong("INSERT_CAMPAIGN_AD_EXTENSION_ID_HERE");

      // Create ad extension override.
      AdExtensionOverride adExtensionOverride = new AdExtensionOverride();
      adExtensionOverride.setAdId(adId);

      // Create ad extension using existing id.
      AdExtension adExtension = new AdExtension();
      adExtension.setId(campaignAdExtensionId);
      adExtensionOverride.setAdExtension(adExtension);

      // Create operations.
      AdExtensionOverrideOperation operation = new AdExtensionOverrideOperation();
      operation.setOperand(adExtensionOverride);
      operation.setOperator(Operator.ADD);

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

      // Add ad extension override.
      AdExtensionOverrideReturnValue result = adExtensionOverrideService.mutate(operations);

      // Display ad extension overrides.
      if (result != null && result.getValue() != null) {
        for (AdExtensionOverride adExtensionOverrideResult : result.getValue()) {
          System.out.println("Ad extension override with ad id \""
View Full Code Here

          user.getService(AdWordsService.V201306.ADGROUP_SERVICE);

      long adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");

      // Create ad group with DELETED status.
      AdGroup adGroup = new AdGroup();
      adGroup.setId(adGroupId);
      adGroup.setStatus(AdGroupStatus.DELETED);

      // Create operations.
      AdGroupOperation operation = new AdGroupOperation();
      operation.setOperand(adGroup);
      operation.setOperator(Operator.SET);
View Full Code Here

          user.getService(AdWordsService.V201306.ADGROUP_SERVICE);

      long adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");

      // Create ad group with updated status.
      AdGroup adGroup = new AdGroup();
      adGroup.setId(adGroupId);
      adGroup.setStatus(AdGroupStatus.PAUSED);

      // Create operations.
      AdGroupOperation operation = new AdGroupOperation();
      operation.setOperand(adGroup);
      operation.setOperator(Operator.SET);
View Full Code Here

      exemptableTextAd.setDescription2("Low-gravity fun for everyone!");
      exemptableTextAd.setDisplayUrl("www.example.com");
      exemptableTextAd.setUrl("http://www.example.com/");

      // Create ad group ad.
      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);
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

      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);
            }
          }
        }

        // Remove operations that cannot be exempted.
        List<AdGroupAdOperation> remainingOperations = new ArrayList<AdGroupAdOperation>();
        for (int i = 0; i < operations.length; i++) {
          if (!indicesToRemove.contains(i)) {
            remainingOperations.add(operations[i]);
          }
        }
        operations = remainingOperations.toArray(new AdGroupAdOperation[]{});
      }

      if (operations.length > 0) {
        // Add ads with exemptions.
        AdGroupAdReturnValue result = adGroupAdService.mutate(operations);

        // Display ads.
        if (result != null && result.getValue() != null) {
          for (AdGroupAd adGroupAdResult : result.getValue()) {
            System.out.printf("Ad with id \"%s\" and headline \"%s\" was added.\n", adGroupAdResult
                .getAd().getId(), ((TextAd) adGroupAdResult.getAd()).getHeadline());
          }
        }
      } else {
View Full Code Here

TOP

Related Classes of com.google.api.adwords.v201306.cm.AuthenticationError

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.