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

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


    selector.setPaging(new Paging(offset, PAGE_SIZE));
    selector.setOrdering(new OrderBy[] {new OrderBy("MediaId", SortOrder.ASCENDING)});
    selector.setPaging(new Paging(offset, PAGE_SIZE));

    // Create predicates.
    Predicate typePredicate =
        new Predicate("Type", PredicateOperator.IN, new String[] {"IMAGE", "VIDEO"});
    selector.setPredicates(new Predicate[] {typePredicate});

    MediaPage page = null;

    do {
View Full Code Here


  }

  public static void runExample(AdWordsServices adWordsServices, AdWordsSession session,
      Long feedId, Map<Long, String[]> feedItemDescriptions) throws Exception {
    FeedServiceInterface feedService = adWordsServices.get(session, FeedServiceInterface.class);
    Selector selector = new Selector();
    // Do not include "Attributes" because you do not want to pass existing
    // attributes into the subsequent mutate (SET) call.
    selector.setFields(new String[] {"Id", "Attributes"});
    selector.setPredicates(new Predicate[] {
        new Predicate("Id", PredicateOperator.EQUALS, new String[] {feedId.toString()})});
    Feed feed = feedService.get(selector).getEntries()[0];

    // Add new attributes to the feed.
    FeedAttribute[] newAttributes = addLine1And2FeedAttributes(adWordsServices, session, feed);
View Full Code Here

  private static void updateFeedItems(AdWordsServices adWordsServices, AdWordsSession session,
      Long feedId, FeedAttribute line1Attribute, FeedAttribute line2Attribute,
      Map<Long, String[]> feedItemDescriptions) throws Exception {
    FeedItemServiceInterface feedItemService =
        adWordsServices.get(session, FeedItemServiceInterface.class);
    Selector itemSelector = new Selector();
    itemSelector.setFields(new String[] {"FeedId", "FeedItemId", "AttributeValues"});

    List<String> feedItemIds = Lists.newArrayList(
        Iterables.transform(feedItemDescriptions.keySet(), Functions.toStringFunction()));
    itemSelector.setPredicates(new Predicate[] {
        // Limit FeedItems to the feed.
        new Predicate("FeedId", PredicateOperator.EQUALS, new String[] {feedId.toString()}),
        // Limit FeedItems to the items in the feedItemDescriptions map.
        new Predicate("FeedItemId", PredicateOperator.IN, feedItemIds.toArray(new String[0]))});
View Full Code Here

  private static void updateFeedMapping(AdWordsServices adWordsServices, AdWordsSession session,
      Long feedId, FeedAttribute line1FeedAttribute, FeedAttribute line2FeedAttribute)
      throws Exception {
    FeedMappingServiceInterface mappingService =
        adWordsServices.get(session, FeedMappingServiceInterface.class);
    Selector selector = new Selector();
    selector.setFields(
        new String[] {"FeedId", "FeedMappingId", "PlaceholderType", "AttributeFieldMappings"});
    selector.setPredicates(new Predicate[] {
        new Predicate("FeedId", PredicateOperator.EQUALS, new String[] {feedId.toString()})});

    FeedMapping feedMapping = mappingService.get(selector).getEntries()[0];

    // Remove the existing mapping (FeedMapping is immutable).
View Full Code Here

        adWordsServices.get(session, MediaServiceInterface.class);

    int offset = 0;

    // Create selector.
    Selector selector = new Selector();
    selector.setFields(new String[] {"MediaId", "Width", "Height", "MimeType"});
    selector.setPaging(new Paging(offset, PAGE_SIZE));
    selector.setOrdering(new OrderBy[] {new OrderBy("MediaId", SortOrder.ASCENDING)});
    selector.setPaging(new Paging(offset, PAGE_SIZE));

    // Create predicates.
    Predicate typePredicate =
        new Predicate("Type", PredicateOperator.IN, new String[] {"IMAGE", "VIDEO"});
    selector.setPredicates(new Predicate[] {typePredicate});

    MediaPage page = null;

    do {
      // Get all images.
      page = mediaService.get(selector);

      // Display images.
      if (page != null && page.getEntries() != null) {
        for (Media media : page.getEntries()) {
          Map<MediaSize, Dimensions> dimensions = Maps.toMap(media.getDimensions());
          System.out.println("Media with id '" + media.getMediaId() +
              (!dimensions.isEmpty()
                  ? "', dimensions '" + dimensions.get(MediaSize.FULL).getWidth() + "x"
                    + dimensions.get(MediaSize.FULL).getHeight()
                  : "") + "', and MIME type '"
              + media.getMediaType() + "' was found.");
        }
      } else {
        System.out.println("No images/videos were found.");
      }
      offset += PAGE_SIZE;
      selector.getPaging().setStartIndex(offset);
    } while (offset < page.getTotalNumEntries());
  }
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 adGroupAd = new AdGroupAd();
    adGroupAd.setAdGroupId(adGroup.getId());
    adGroupAd.setAd(productAd);

    // Create operation.
    AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation();
    adGroupAdOperation.setOperand(adGroupAd);
    adGroupAdOperation.setOperator(Operator.ADD);

    // Make the mutate request.
    AdGroupAdReturnValue adGroupAdAddResult =
        adGroupAdService.mutate(new AdGroupAdOperation[] {adGroupAdOperation});
View Full Code Here

    textAdGroupAd2.setAdGroupId(adGroupId);
    textAdGroupAd2.setAd(textAd2);


    // Create operations.
    AdGroupAdOperation textAdGroupAdOperation1 = new AdGroupAdOperation();
    textAdGroupAdOperation1.setOperand(textAdGroupAd1);
    textAdGroupAdOperation1.setOperator(Operator.ADD);
    AdGroupAdOperation textAdGroupAdOperation2 = new AdGroupAdOperation();
    textAdGroupAdOperation2.setOperand(textAdGroupAd2);
    textAdGroupAdOperation2.setOperator(Operator.ADD);

    AdGroupAdOperation[] operations =
        new AdGroupAdOperation[] {textAdGroupAdOperation1, textAdGroupAdOperation2};

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

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.