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

Examples of com.google.api.ads.adwords.axis.v201309.cm.AdGroupAdReturnValue


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

    try {
      // Validate the ads.
      AdGroupAdReturnValue result = adGroupAdService.mutate(operations);
    } catch (ApiException e) {
      Set<Integer> indicesToRemove = new HashSet<Integer>();
      for (ApiError error : e.getErrors()) {
        if (error instanceof PolicyViolationError) {
          PolicyViolationError policyViolationError = (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(), policyViolationError
                    .getIsExemptable() ? "exemptable" : "non-exemptable", policyViolationError
                    .getExternalPolicyName());
            if (policyViolationError.getIsExemptable()) {
              // Add exemption request to the operation.
              System.out.printf(
                  "Adding exemption request for policy name \"%s\" on text \"%s\".\n",
                  policyViolationError.getKey().getPolicyName(), policyViolationError.getKey()
                      .getViolatingText());
              List<ExemptionRequest> exemptionRequests =
                  new ArrayList<ExemptionRequest>(Arrays
                      .asList(operation.getExemptionRequests() == null
                          ? new ExemptionRequest[] {} : operation.getExemptionRequests()));
              exemptionRequests.add(new ExemptionRequest(policyViolationError.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) {
      // Disable validateOnly so we can submit the AdGroupAds with exemptions.
      session.setValidateOnly(false);

      // 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


    operation.setOperator(Operator.SET);

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

    // Update ad.
    AdGroupAdReturnValue result = adGroupAdService.mutate(operations);

    // Display ads.
    for (AdGroupAd adGroupAdResult : result.getValue()) {
      System.out.println("Ad with id \"" + adGroupAdResult.getAd().getId() + "\", type \""
          + adGroupAdResult.getAd().getAdType() + "\", and status \"" + adGroupAdResult.getStatus()
          + "\" was updated.");
    }
  }
View Full Code Here

    operation.setOperator(Operator.REMOVE);

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

    // Delete ad.
    AdGroupAdReturnValue result = adGroupAdService.mutate(operations);

    // Display ads.
    for (AdGroupAd adGroupAdResult : result.getValue()) {
      System.out.println("Ad with id \"" + adGroupAdResult.getAd().getId() + "\" and type \""
          + adGroupAdResult.getAd().getAdType() + "\" was deleted.");
    }
  }
View Full Code Here

    AdGroupAdOperation[] operations =
        new AdGroupAdOperation[] {adGroupAdOperation, adGroupAdOperation2};

    // Add ads.
    AdGroupAdReturnValue result = adGroupAdService.mutate(operations);

    // Display ads.
    for (AdGroupAd adGroupAdResult : result.getValue()) {
      System.out.println("Ad with id  \"" + adGroupAdResult.getAd().getId() + "\"" + " and type \""
          + adGroupAdResult.getAd().getAdType() + "\" was added.");
    }
  }
View Full Code Here

    // Remove the existing mapping (FeedMapping is immutable).
    feedMapping = mappingService.mutate(new FeedMappingOperation[] {
        new FeedMappingOperation(Operator.REMOVE, null, feedMapping)}).getValue(0);

    // Create line 1 and line 2 attribute field mappings.
    AttributeFieldMapping line1FieldMapping = new AttributeFieldMapping();
    line1FieldMapping.setFeedAttributeId(line1FeedAttribute.getId());
    line1FieldMapping.setFieldId(PLACEHOLDER_FIELD_LINE_1_TEXT);

    AttributeFieldMapping line2FieldMapping = new AttributeFieldMapping();
    line2FieldMapping.setFeedAttributeId(line2FeedAttribute.getId());
    line2FieldMapping.setFieldId(PLACEHOLDER_FIELD_LINE_2_TEXT);

    // Combine the existing field mappings with the new mappings.
    List<AttributeFieldMapping> allFieldMappings = new ArrayList<AttributeFieldMapping>();

    // Include existing mappings.
View Full Code Here

    // Get the FeedItemService.
    FeedMappingServiceInterface feedMappingService =
        adWordsServices.get(session, FeedMappingServiceInterface.class);

    // Map the FeedAttributeIds to the fieldId constants.
    AttributeFieldMapping linkTextFieldMapping = new AttributeFieldMapping();
    linkTextFieldMapping.setFeedAttributeId(siteLinksData.linkTextFeedAttributeId);
    linkTextFieldMapping.setFieldId(PLACEHOLDER_FIELD_SITELINK_LINK_TEXT);
    AttributeFieldMapping linkUrlFieldMapping = new AttributeFieldMapping();
    linkUrlFieldMapping.setFeedAttributeId(siteLinksData.linkUrlFeedAttributeId);
    linkUrlFieldMapping.setFieldId(PLACEHOLDER_FIELD_SITELINK_URL);
    AttributeFieldMapping line1FieldMapping = new AttributeFieldMapping();
    line1FieldMapping.setFeedAttributeId(siteLinksData.line1FeedAttributeId);
    line1FieldMapping.setFieldId(PLACEHOLDER_FIELD_LINE_1_TEXT);
    AttributeFieldMapping line2FieldMapping = new AttributeFieldMapping();
    line2FieldMapping.setFeedAttributeId(siteLinksData.line2FeedAttributeId);
    line2FieldMapping.setFieldId(PLACEHOLDER_FIELD_LINE_2_TEXT);


    // Create the FieldMapping and operation.
    FeedMapping feedMapping = new FeedMapping();
    feedMapping.setPlaceholderType(PLACEHOLDER_SITELINKS);
View Full Code Here

    Function combinedFunction = new Function();
    combinedFunction.setOperator(FunctionOperator.AND);
    combinedFunction.setLhsOperand(
        new FunctionArgumentOperand[] {feedItemFunctionOperand, platformFunctionOperand});

    CampaignFeed campaignFeed = new CampaignFeed();
    campaignFeed.setFeedId(siteLinksData.siteLinksFeedId);
    campaignFeed.setCampaignId(campaignId);
    campaignFeed.setMatchingFunction(combinedFunction);
    // Specifying placeholder types on the CampaignFeed allows the same feed
    // to be used for different placeholders in different Campaigns.
    campaignFeed.setPlaceholderTypes(new int[] {PLACEHOLDER_SITELINKS});

    CampaignFeedOperation operation = new CampaignFeedOperation();
    operation.setOperand(campaignFeed);
    operation.setOperator(Operator.ADD);
    CampaignFeedReturnValue result =
View Full Code Here

    campaignFeed.setMatchingFunction(combinedFunction);
    // Specifying placeholder types on the CampaignFeed allows the same feed
    // to be used for different placeholders in different Campaigns.
    campaignFeed.setPlaceholderTypes(new int[] {PLACEHOLDER_SITELINKS});

    CampaignFeedOperation operation = new CampaignFeedOperation();
    operation.setOperand(campaignFeed);
    operation.setOperator(Operator.ADD);
    CampaignFeedReturnValue result =
        campaignFeedService.mutate(new CampaignFeedOperation[] {operation});
    for (CampaignFeed savedCampaignFeed : result.getValue()) {
      System.out.printf("Campaign with ID %d was associated with feed with ID %d.\n",
          savedCampaignFeed.getCampaignId(), savedCampaignFeed.getFeedId());
View Full Code Here

    campaignFeed.setPlaceholderTypes(new int[] {PLACEHOLDER_SITELINKS});

    CampaignFeedOperation operation = new CampaignFeedOperation();
    operation.setOperand(campaignFeed);
    operation.setOperator(Operator.ADD);
    CampaignFeedReturnValue result =
        campaignFeedService.mutate(new CampaignFeedOperation[] {operation});
    for (CampaignFeed savedCampaignFeed : result.getValue()) {
      System.out.printf("Campaign with ID %d was associated with feed with ID %d.\n",
          savedCampaignFeed.getCampaignId(), savedCampaignFeed.getFeedId());
    }
  }
View Full Code Here

  }

  private static void createSiteLinksCampaignFeed(AdWordsServices adWordsServices,
      AdWordsSession session, SiteLinksDataHolder siteLinksData, Long campaignId) throws Exception {
    // Get the CampaignFeedService.
    CampaignFeedServiceInterface campaignFeedService =
        adWordsServices.get(session, CampaignFeedServiceInterface.class);

    RequestContextOperand requestContextOperand = new RequestContextOperand();
    requestContextOperand.setContextType(RequestContextOperandContextType.FEED_ITEM_ID);

    Function feedItemFunction = new Function();
    feedItemFunction.setLhsOperand(new FunctionArgumentOperand[] {requestContextOperand});
    feedItemFunction.setOperator(FunctionOperator.IN);

    List<FunctionArgumentOperand> operands = new ArrayList<FunctionArgumentOperand>();
    for (long feedItemId : siteLinksData.siteLinkFeedItemIds) {
      ConstantOperand constantOperand = new ConstantOperand();
      constantOperand.setLongValue(feedItemId);
      constantOperand.setType(ConstantOperandConstantType.LONG);
      operands.add(constantOperand);
    }
    feedItemFunction.setRhsOperand(operands.toArray(new FunctionArgumentOperand[operands.size()]));

    // Optional: to target to a platform, define a function and 'AND' it with
    // the feed item ID link:
    RequestContextOperand platformRequestContextOperand = new RequestContextOperand();
    platformRequestContextOperand.setContextType(RequestContextOperandContextType.DEVICE_PLATFORM);

    ConstantOperand platformOperand = new ConstantOperand();
    platformOperand.setStringValue("Mobile");
    platformOperand.setType(ConstantOperandConstantType.STRING);

    Function platformFunction = new Function();
    platformFunction.setLhsOperand(new FunctionArgumentOperand[] {platformRequestContextOperand});
    platformFunction.setOperator(FunctionOperator.EQUALS);
    platformFunction.setRhsOperand(new FunctionArgumentOperand[] {platformOperand});

    // Combine the two functions using an AND operation.
    FunctionOperand feedItemFunctionOperand = new FunctionOperand();
    feedItemFunctionOperand.setValue(feedItemFunction);

    FunctionOperand platformFunctionOperand = new FunctionOperand();
    platformFunctionOperand.setValue(platformFunction);

    Function combinedFunction = new Function();
    combinedFunction.setOperator(FunctionOperator.AND);
    combinedFunction.setLhsOperand(
        new FunctionArgumentOperand[] {feedItemFunctionOperand, platformFunctionOperand});

    CampaignFeed campaignFeed = new CampaignFeed();
    campaignFeed.setFeedId(siteLinksData.siteLinksFeedId);
    campaignFeed.setCampaignId(campaignId);
    campaignFeed.setMatchingFunction(combinedFunction);
    // Specifying placeholder types on the CampaignFeed allows the same feed
    // to be used for different placeholders in different Campaigns.
    campaignFeed.setPlaceholderTypes(new int[] {PLACEHOLDER_SITELINKS});

    CampaignFeedOperation operation = new CampaignFeedOperation();
    operation.setOperand(campaignFeed);
    operation.setOperator(Operator.ADD);
    CampaignFeedReturnValue result =
        campaignFeedService.mutate(new CampaignFeedOperation[] {operation});
    for (CampaignFeed savedCampaignFeed : result.getValue()) {
      System.out.printf("Campaign with ID %d was associated with feed with ID %d.\n",
          savedCampaignFeed.getCampaignId(), savedCampaignFeed.getFeedId());
    }
  }
View Full Code Here

TOP

Related Classes of com.google.api.ads.adwords.axis.v201309.cm.AdGroupAdReturnValue

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.