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

Examples of com.google.api.adwords.v201309.cm.AdGroupAdServiceInterface


  }

  public static void runExample(
      AdWordsServices adWordsServices, AdWordsSession session, Long adGroupId) throws Exception {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService =
        adWordsServices.get(session, AdGroupAdServiceInterface.class);

    int offset = 0;
    boolean morePages = true;

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

    // Create predicates.
    Predicate adGroupIdPredicate =
        new Predicate("AdGroupId", PredicateOperator.IN, new String[] {adGroupId.toString()});
    // By default disabled ads aren't returned by the selector. To return them
    // include the DISABLED status in a predicate.
    Predicate statusPredicate =
        new Predicate("Status", PredicateOperator.IN,
            new String[] {"ENABLED", "PAUSED", "DISABLED"});
    Predicate adTypePredicate =
        new Predicate("AdType", PredicateOperator.EQUALS, new String[] {"TEXT_AD"});
    selector.setPredicates(new Predicate[] {adGroupIdPredicate, statusPredicate, adTypePredicate});

    while (morePages) {
      // Get all ads.
      AdGroupAdPage page = adGroupAdService.get(selector);

      // Display ads.
      if (page.getEntries() != null && page.getEntries().length > 0) {
        for (AdGroupAd adGroupAd : page.getEntries()) {
          System.out.println("Ad with id  \"" + adGroupAd.getAd().getId() + "\"" + " and type \""
View Full Code Here


  }

  public static void runExample(
      AdWordsServices adWordsServices, AdWordsSession session, long adGroupId) throws Exception {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService =
        adWordsServices.get(session, AdGroupAdServiceInterface.class);

    // Create the template ad.
    TemplateAd clickToDownloadAppAd = new TemplateAd();
    clickToDownloadAppAd.setName("Ad for jupiter adventure game");
    clickToDownloadAppAd.setTemplateId(353L);

    clickToDownloadAppAd.setUrl(
        "http://play.google.com/store/apps/details?id=com.example.jupiteradventure");
    clickToDownloadAppAd.setDisplayUrl("play.google.com");

    // Create the template elements for the ad. You can refer to
    // https://developers.google.com/adwords/api/docs/appendix/templateads
    // for the list of available template fields.
    TemplateElementField headline = new TemplateElementField();
    headline.setName("headline");
    headline.setFieldText("Enjoy a Jupiter Adventure");
    headline.setType(TemplateElementFieldType.TEXT);

    TemplateElementField description1 = new TemplateElementField();
    description1.setName("description1");
    description1.setFieldText("Realistic physics simulation");
    description1.setType(TemplateElementFieldType.TEXT);

    TemplateElementField description2 = new TemplateElementField();
    description2.setName("description2");
    description2.setFieldText("Race against players online");
    description2.setType(TemplateElementFieldType.TEXT);

    TemplateElementField appId = new TemplateElementField();
    appId.setName("appId");
    appId.setFieldText("com.example.jupiteradventure");
    appId.setType(TemplateElementFieldType.TEXT);

    TemplateElementField appStore = new TemplateElementField();
    appStore.setName("appStore");
    appStore.setFieldText("2");
    appStore.setType(TemplateElementFieldType.ENUM);

    TemplateElement adData = new TemplateElement();
    adData.setUniqueName("adData");
    adData.setFields(new TemplateElementField[] {headline, description1, description2, appId,
        appStore});

    clickToDownloadAppAd.setTemplateElements(new TemplateElement[] {adData});

    // Create the AdGroupAd.
    AdGroupAd clickToDownloadAppAdGroupAd = new AdGroupAd();
    clickToDownloadAppAdGroupAd.setAdGroupId(adGroupId);
    clickToDownloadAppAdGroupAd.setAd(clickToDownloadAppAd);

    // Optional: Set the status.
    clickToDownloadAppAdGroupAd.setStatus(AdGroupAdStatus.PAUSED);

    // Create the operation.
    AdGroupAdOperation operation = new AdGroupAdOperation();
    operation.setOperator(Operator.ADD);
    operation.setOperand(clickToDownloadAppAdGroupAd);

    // Create the ads.
    AdGroupAdReturnValue result = adGroupAdService.mutate(new AdGroupAdOperation[] {operation});

    for (AdGroupAd adGroupAd : result.getValue()) {
      System.out.printf("New click-to-download ad with id = \"%d\" and url = \"%s\" " +
          "was created.", adGroupAd.getAd().getId(), adGroupAd.getAd().getUrl());
    }
View Full Code Here

  }

  public static void runExample(
      AdWordsServices adWordsServices, AdWordsSession session, long adGroupId) throws Exception {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService =
        adWordsServices.get(session, AdGroupAdServiceInterface.class);

    // Create text ad.
    TextAd textAd1 = new TextAd();
    textAd1.setHeadline("Luxury Cruise to Mars");
    textAd1.setDescription1("Visit the Red Planet in style.");
    textAd1.setDescription2("Low-gravity fun for everyone!");
    textAd1.setDisplayUrl("www.example.com");
    textAd1.setUrl("http://www.example.com");
    TextAd textAd2 = new TextAd();
    textAd2.setHeadline("Luxury Cruise to Mars");
    textAd2.setDescription1("Enjoy your stay at Red Planet.");
    textAd2.setDescription2("Buy your tickets now!");
    textAd2.setDisplayUrl("www.example.com");
    textAd2.setUrl("http://www.example.com");


    // Create ad group ad.
    AdGroupAd textAdGroupAd1 = new AdGroupAd();
    textAdGroupAd1.setAdGroupId(adGroupId);
    textAdGroupAd1.setAd(textAd1);

    // You can optionally provide these field(s).
    textAdGroupAd1.setStatus(AdGroupAdStatus.PAUSED);

    AdGroupAd textAdGroupAd2 = new AdGroupAd();
    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.
    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

  }

  public static void runExample(
      AdWordsServices adWordsServices, AdWordsSession session, Long adGroupId) throws Exception {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService =
        adWordsServices.get(session, AdGroupAdServiceInterface.class);

    int offset = 0;
    boolean morePages = true;

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

    // Create predicates.
    Predicate adGroupIdPredicate =
        new Predicate("AdGroupId", PredicateOperator.IN, new String[] {adGroupId.toString()});
    // By default disabled ads aren't returned by the selector. To return them
    // include the DISABLED status in a predicate.
    Predicate statusPredicate =
        new Predicate("Status", PredicateOperator.IN,
            new String[] {"ENABLED", "PAUSED", "DISABLED"});
    Predicate adTypePredicate =
        new Predicate("AdType", PredicateOperator.EQUALS, new String[] {"TEXT_AD"});
    selector.setPredicates(new Predicate[] {adGroupIdPredicate, statusPredicate, adTypePredicate});

    while (morePages) {
      // Get all ads.
      AdGroupAdPage page = adGroupAdService.get(selector);

      // Display ads.
      if (page.getEntries() != null && page.getEntries().length > 0) {
        for (AdGroupAd adGroupAd : page.getEntries()) {
          System.out.println("Ad with id  \"" + adGroupAd.getAd().getId() + "\"" + " and type \""
View Full Code Here

  }

  public static void runExample(
      AdWordsServices adWordsServices, AdWordsSession session, Long adGroupId) throws Exception {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService =
        adWordsServices.get(session, AdGroupAdServiceInterface.class);

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

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

    // Get all disapproved ads.
    AdGroupAdPage page = adGroupAdService.get(selector);

    // Display ads.
    if (page.getEntries() != null && page.getEntries().length > 0) {
      for (AdGroupAd adGroupAd : page.getEntries()) {
        System.out.println("Ad with id \"" + adGroupAd.getAd().getId() + "\"" + " and type \""
View Full Code Here

      AdWordsServices adWordsServices, AdWordsSession session, Long adGroupId) throws Exception {
    // Enable validation.
    session.setValidateOnly(true);

    // Get the validation AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdValidationService =
        adWordsServices.get(session, AdGroupAdServiceInterface.class);

    // Create text ad.
    TextAd textAd1 = new TextAd();
    textAd1.setHeadline("Luxury Cruise to Mars");
    textAd1.setDescription1("Visit the Red Planet in style.");
    textAd1.setDescription2("Low-gravity fun for everyone!");
    textAd1.setDisplayUrl("www.example.com");
    textAd1.setUrl("http://www.example.com");

    // Create ad group ad.
    AdGroupAd textAdGroupAd1 = new AdGroupAd();
    textAdGroupAd1.setAdGroupId(adGroupId);
    textAdGroupAd1.setAd(textAd1);

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

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

    // Add ads.
    AdGroupAdReturnValue result = adGroupAdValidationService.mutate(operations);
    // No error means the request is valid.

    // Now let's check an invalid ad using a very long line to trigger an error.
    textAd1.setDescription2("Low-gravity fun for all astronauts in orbit.");

    try {
      adGroupAdValidationService.mutate(operations);
    } catch (ApiException e) {
      System.err.println("Validation failed for reason \"" + e.getMessage1() + "\".");
    }
  }
View Full Code Here

  }

  public static void runExample(
      AdWordsServices adWordsServices, AdWordsSession session, Long adGroupId) throws Exception {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService =
        adWordsServices.get(session, AdGroupAdServiceInterface.class);

    String query = String.format("SELECT Id, AdGroupAdDisapprovalReasons "
        + "WHERE AdGroupId = %d AND AdGroupCreativeApprovalStatus = DISAPPROVED ORDER BY Id",
        adGroupId);

    // Get all disapproved ads.
    AdGroupAdPage page = adGroupAdService.query(query);

    // Display ads.
    if (page.getEntries() != null && page.getEntries().length > 0) {
      for (AdGroupAd adGroupAd : page.getEntries()) {
        System.out.println("Ad with id \"" + adGroupAd.getAd().getId() + "\"" + " and type \""
View Full Code Here

      AdWordsServices adWordsServices, AdWordsSession session, Long adGroupId) throws Exception {
    // Enable validateOnly mode.
    session.setValidateOnly(true);

    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService =
        adWordsServices.get(session, AdGroupAdServiceInterface.class);

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

  public static void runExample(
      AdWordsServices adWordsServices, AdWordsSession session, Long adGroupId, Long adId)
      throws Exception {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService =
        adWordsServices.get(session, AdGroupAdServiceInterface.class);

    // Create ad with updated status.
    Ad ad = new Ad();
    ad.setId(adId);

    AdGroupAd adGroupAd = new AdGroupAd();
    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);

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

  public static void runExample(
      AdWordsServices adWordsServices, AdWordsSession session, long adGroupId, long adId)
      throws Exception {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService =
        adWordsServices.get(session, AdGroupAdServiceInterface.class);

    // Create base class ad to avoid setting type specific fields.
    Ad ad = new Ad();
    ad.setId(adId);

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

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

TOP

Related Classes of com.google.api.adwords.v201309.cm.AdGroupAdServiceInterface

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.