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

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


          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

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

      // Get the AdGroupAdService.
      AdGroupAdServiceInterface adGroupAdService =
          user.getService(AdWordsService.V201306.ADGROUP_AD_SERVICE);

      // Get validateOnly version of the AdGroupAdService.
      AdGroupAdServiceInterface adGroupAdValidationService =
          user.getValidationService(AdWordsService.V201306.ADGROUP_AD_SERVICE);

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

      // Create text ad that violates an exemptable policy. This ad will only
      // trigger an error in the production environment.
      TextAd exemptableTextAd = new TextAd();
      exemptableTextAd.setHeadline("Mars " + System.currentTimeMillis() + "!!!");
      exemptableTextAd.setDescription1("Visit the Red Planet in style.");
      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);

      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;
View Full Code Here

      Predicate adGroupIdPredicate =
          new Predicate("AdGroupId", PredicateOperator.IN, new String[] {adGroupId.toString()});
      selector.setPredicates(new Predicate[] {adGroupIdPredicate});

      // Get bid landscape for ad group criteria.
      AdGroupBidLandscapePage page = dataService.getAdGroupBidLandscape(selector);

      // Display bid landscapes.
      if (page.getEntries() != null) {
        for (AdGroupBidLandscape adGroupBidLandscape : page.getEntries()) {
          System.out.println("Ad group bid landscape with ad group id \""
              + adGroupBidLandscape.getAdGroupId() + "\", type \""
              + adGroupBidLandscape.getType() + "\", current \""
              + adGroupBidLandscape.getLandscapeCurrent() + "\", start date \""
              + adGroupBidLandscape.getStartDate() + "\", end date \""
View Full Code Here

        // Create BiddableAdGroupCriterion.
        BiddableAdGroupCriterion bagc = new BiddableAdGroupCriterion();
        bagc.setAdGroupId(adGroupId);
        bagc.setCriterion(keyword);
        // Create AdGroupCriterionOperation.
        AdGroupCriterionOperation agco = new AdGroupCriterionOperation();
        agco.setOperand(bagc);
        agco.setOperator(Operator.ADD);
        // Add to list.
        operations.add(agco);
      }

      // You can specify up to 3 job IDs that must successfully complete before
View Full Code Here

      Predicate adGroupIdPredicate =
          new Predicate("AdGroupId", PredicateOperator.IN, new String[] {adGroupId.toString()});
      selector.setPredicates(new Predicate[] {statusPredicate, adGroupIdPredicate});

      // Get all active ad group criteria.
      AdGroupCriterionPage page = adGroupCriterionService.get(selector);

      // Display ad group criteria.
      if (page.getEntries() != null && page.getEntries().length > 0) {
        for (AdGroupCriterion adGroupCriterion : page.getEntries()) {
          if (adGroupCriterion instanceof BiddableAdGroupCriterion) {
            BiddableAdGroupCriterion biddableAdGroupCriterion =
                (BiddableAdGroupCriterion) adGroupCriterion;
            System.out.println("Ad group criterion with ad group id \""
                + biddableAdGroupCriterion.getAdGroupId() + "\", criterion id \""
View Full Code Here

      String query = String.format(
          "SELECT Id, AdGroupId, Status WHERE AdGroupId = %d AND Status = ACTIVE ORDER BY Id ",
          adGroupId);

      // Get all active ad group criteria.
      AdGroupCriterionPage page = adGroupCriterionService.query(query);

      // Display ad group criteria.
      if (page.getEntries() != null && page.getEntries().length > 0) {
        for (AdGroupCriterion adGroupCriterion : page.getEntries()) {
          if (adGroupCriterion instanceof BiddableAdGroupCriterion) {
            BiddableAdGroupCriterion biddableAdGroupCriterion =
                (BiddableAdGroupCriterion) adGroupCriterion;
            System.out.println("Ad group criterion with ad group id \""
                + biddableAdGroupCriterion.getAdGroupId() + "\", criterion id \""
View Full Code Here

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

      // Get the AdGroupCriterionService.
      AdGroupCriterionServiceInterface adGroupCriterionService =
          user.getService(AdWordsService.V201306.ADGROUP_CRITERION_SERVICE);

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

      // Create selector.
      Selector selector = new Selector();
      selector.setFields(new String[] {"Id", "AdGroupId", "Status"});
      selector.setOrdering(new OrderBy[] {new OrderBy("Id", SortOrder.ASCENDING)});

      // Create predicates.
      Predicate statusPredicate =
          new Predicate("Status", PredicateOperator.IN, new String[] {"ACTIVE"});
      Predicate adGroupIdPredicate =
          new Predicate("AdGroupId", PredicateOperator.IN, new String[] {adGroupId.toString()});
      selector.setPredicates(new Predicate[] {statusPredicate, adGroupIdPredicate});

      // Get all active ad group criteria.
      AdGroupCriterionPage page = adGroupCriterionService.get(selector);

      // Display ad group criteria.
      if (page.getEntries() != null && page.getEntries().length > 0) {
        for (AdGroupCriterion adGroupCriterion : page.getEntries()) {
          if (adGroupCriterion instanceof BiddableAdGroupCriterion) {
View Full Code Here

TOP

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

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.