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

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


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

    AdGroupAd adGroupAd2 = new AdGroupAd();
    adGroupAd2.setAdGroupId(adGroupId);
    adGroupAd2.setAd(inStreamVideo);

    // Create operations.
    AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation();
    adGroupAdOperation.setOperand(adGroupAd1);
    adGroupAdOperation.setOperator(Operator.ADD);
    AdGroupAdOperation adGroupAdOperation2 = new AdGroupAdOperation();
    adGroupAdOperation2.setOperand(adGroupAd2);
    adGroupAdOperation2.setOperator(Operator.ADD);

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

    // Add ads.
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.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.