Package com.google.api.ads.dfp.v201211

Examples of com.google.api.ads.dfp.v201211.Date


      // Get the CustomTargetingService.
      CustomTargetingServiceInterface customTargetingService =
          user.getService(DfpService.V201211.CUSTOM_TARGETING_SERVICE);

      // Sets defaults for page and filter.
      CustomTargetingKeyPage keyPage = new CustomTargetingKeyPage();
      Statement keyFilterStatement = new Statement();
      int keyOffset = 0;

      do {
        // Create a statement to get all custom targeting keys.
        keyFilterStatement.setQuery("LIMIT 500 OFFSET " + keyOffset);

        // Get custom targeting keys by statement.
        keyPage = customTargetingService.getCustomTargetingKeysByStatement(keyFilterStatement);

        if (keyPage.getResults() != null) {
          int i = keyPage.getStartIndex();
          for (CustomTargetingKey key : keyPage.getResults()) {
            System.out.println(i + ") Custom targeting key with ID \"" + key.getId()
                + "\", name \"" + key.getName() + "\", display name \"" + key.getDisplayName()
                + "\", and type \"" + key.getType() + "\" was found.");


            // Sets defaults for page and filter.
            CustomTargetingValuePage valuePage = new CustomTargetingValuePage();
            Statement valueFilterStatement = new Statement();
            int valueOffset = 0;

            do {
              // Create a statement to get all custom targeting values for a
              // custom targeting key (required) by its ID.
              valueFilterStatement.setQuery("WHERE customTargetingKeyId = " + key.getId()
                  + " LIMIT 500 OFFSET " + valueOffset);

              // Get custom targeting values by statement.
              valuePage =
                  customTargetingService.getCustomTargetingValuesByStatement(valueFilterStatement);

              if (valuePage.getResults() != null) {
                int j = valuePage.getStartIndex();
                for (CustomTargetingValue value : valuePage.getResults()) {
                  System.out.println("\t" + j + ") Custom targeting value with ID \""
                      + value.getId() + "\", name \"" + value.getName() + "\", and display name \""
                      + value.getDisplayName() + "\" was found.");
                  j++;
                }
              }
              valueOffset += 500;
            } while (valuePage.getResults() != null && valuePage.getResults().length == 500);

            i++;
          }
        }
        keyOffset += 500;
      } while (keyPage.getResults() != null && keyPage.getResults().length == 500);

      System.out.println("Number of results found: " + keyPage.getTotalResultSetSize());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
View Full Code Here


      String statementText = "WHERE name = :name";
      StatementBuilder statementBuilder = new StatementBuilder("")
          .putValue("name", customTargetingKeyName);

      // Set defaults for page and offset.
      CustomTargetingKeyPage page = new CustomTargetingKeyPage();
      int offset = 0;
      List<Long> customTargetingKeyIds = new ArrayList<Long>();

      do {
        // Create a statement to page through custom targeting keys.
        statementBuilder.setQuery(statementText + " LIMIT 500 OFFSET " + offset);

        // Get custom targeting keys by statement.
        page = customTargetingService.getCustomTargetingKeysByStatement(
            statementBuilder.toStatement());

        if (page.getResults() != null) {
          for (CustomTargetingKey customTargetingKey : page.getResults()) {
            customTargetingKeyIds.add(customTargetingKey.getId());
          }
        }

        offset += 500;
      } while (offset < page.getTotalResultSetSize());

      System.out.println(
          "Number of custom targeting keys to be deleted: " + customTargetingKeyIds.size());

      if (customTargetingKeyIds.size() > 0) {
View Full Code Here

      // Get the NetworkService.
      NetworkServiceInterface networkService = user.getService(DfpService.V201211.NETWORK_SERVICE);

      // Get the CustomTargetingService.
      CustomTargetingServiceInterface customTargetingService =
          user.getService(DfpService.V201211.CUSTOM_TARGETING_SERVICE);

      // Get content browse custom targeting key ID.
      long contentBrowseCustomTargetingKeyId =
          networkService.getCurrentNetwork().getContentBrowseCustomTargetingKeyId();

      // Create a statement to select the categories matching the name comedy.
      Statement categoryFilterStatement = new StatementBuilder(
          "WHERE customTargetingKeyId = :contentBrowseCustomTargetingKeyId " +
          " and name = :category LIMIT 1")
          .putValue("contentBrowseCustomTargetingKeyId", contentBrowseCustomTargetingKeyId)
          .putValue("category", "comedy").toStatement();

      // Get categories matching the filter statement.
      CustomTargetingValuePage customTargetingValuePage =
          customTargetingService.getCustomTargetingValuesByStatement(categoryFilterStatement);

      // Get the custom targeting value ID for the comedy category.
      long categoryCustomTargetingValueId = customTargetingValuePage.getResults()[0].getId();

      // Set defaults for page and filterStatement.
View Full Code Here

      // Get DfpUser from "~/dfp.properties".
      DfpUser user = new DfpUser();

      // Get the CustomTargetingService.
      CustomTargetingServiceInterface customTargetingService =
          user.getService(DfpService.V201211.CUSTOM_TARGETING_SERVICE);

      // Create a statement to only select predefined custom targeting keys.
      Statement filterStatement = new StatementBuilder("WHERE type = :type LIMIT 500").putValue(
          "type", CustomTargetingKeyType.PREDEFINED.toString()).toStatement();

      // Get custom targeting keys by statement.
      CustomTargetingKeyPage page =
          customTargetingService.getCustomTargetingKeysByStatement(filterStatement);

      if (page.getResults() != null) {
        int i = page.getStartIndex();
        for (CustomTargetingKey customTargetingKey : page.getResults()) {
          System.out.println(i + ") Custom targeting key with ID \"" + customTargetingKey.getId()
View Full Code Here

      // Get DfpUser from "~/dfp.properties".
      DfpUser user = new DfpUser();

      // Get the CustomTargetingService.
      CustomTargetingServiceInterface customTargetingService =
          user.getService(DfpService.V201211.CUSTOM_TARGETING_SERVICE);

      // Set ID of the custom targeting key to delete values from.
      long customTargetingKeyId = Long.parseLong("INSERT_CUSTOM_TARGETING_KEY_ID_HERE");

      // Create statement to only select custom values by the given custom
      // targeting key ID.
      String statementText = "WHERE customTargetingKeyId = :customTargetingKeyId";
      StatementBuilder statementBuilder = new StatementBuilder("")
          .putValue("customTargetingKeyId", customTargetingKeyId);

      // Set defaults for page and offset.
      CustomTargetingValuePage page = new CustomTargetingValuePage();
      int offset = 0;
      List<Long> customTargetingValueIds = new ArrayList<Long>();

      do {
        // Create a statement to page through custom targeting values.
        statementBuilder.setQuery(statementText + " LIMIT 500 OFFSET " + offset);

        // Get custom targeting values by statement.
        page = customTargetingService.getCustomTargetingValuesByStatement(
            statementBuilder.toStatement());

        if (page.getResults() != null) {
          for (CustomTargetingValue customTargetingValue : page.getResults()) {
            customTargetingValueIds.add(customTargetingValue.getId());
          }
        }

        offset += 500;
      } while (offset < page.getTotalResultSetSize());

      System.out.println(
          "Number of custom targeting values to be deleted: " + customTargetingValueIds.size());

      if (customTargetingValueIds.size() > 0) {
        // Modify statement for action.
        statementBuilder.setQuery("WHERE customTargetingKeyId = :customTargetingKeyId AND id IN ("
            + StringUtils.join(customTargetingValueIds, ",") + ")");

        // Create action.
        DeleteCustomTargetingValues action = new DeleteCustomTargetingValues();

        // Perform action.
        UpdateResult result = customTargetingService.performCustomTargetingValueAction(
            action, statementBuilder.toStatement());

        // Display results.
        if (result != null && result.getNumChanges() > 0) {
          System.out.println("Number of custom targeting values deleted: "
View Full Code Here

      // Get DfpUser from "~/dfp.properties".
      DfpUser user = new DfpUser();

      // Get the CustomTargetingService.
      CustomTargetingServiceInterface customTargetingService =
          user.getService(DfpService.V201211.CUSTOM_TARGETING_SERVICE);

      // Create a statement to get all custom targeting keys.
      Statement filterStatement = new Statement("LIMIT 500", null);

      // Get custom targeting keys by statement.
      CustomTargetingKeyPage page =
          customTargetingService.getCustomTargetingKeysByStatement(filterStatement);

      if (page.getResults() != null) {
        CustomTargetingKey[] customTargetingKeys = page.getResults();

        // Update each local custom targeting key object by changing its display
        // name.
        for (CustomTargetingKey customTargetingKey : customTargetingKeys) {
          if (customTargetingKey.getDisplayName() == null) {
            customTargetingKey.setDisplayName(customTargetingKey.getName());
          }
          customTargetingKey.setDisplayName(customTargetingKey.getDisplayName() + " (Deprecated)");
        }

        // Update the custom targeting keys on the server.
        customTargetingKeys = customTargetingService.updateCustomTargetingKeys(customTargetingKeys);

        if (customTargetingKeys != null) {
          for (CustomTargetingKey customTargetingKey : customTargetingKeys) {
            System.out.println("Custom targeting key with ID \""
                + customTargetingKey.getId() + "\", name \"" + customTargetingKey.getName()
View Full Code Here

      // Get DfpUser from "~/dfp.properties".
      DfpUser user = new DfpUser();

      // Get the CustomTargetingService.
      CustomTargetingServiceInterface customTargetingService =
          user.getService(DfpService.V201211.CUSTOM_TARGETING_SERVICE);

      // Set the ID of the custom targeting key to get custom targeting values
      // for.
      long customTargetingKeyId = Long.parseLong("INSERT_CUSTOM_TARGETING_KEY_ID_HERE");

      // Create a statement to only select custom targeting values for a given
      // key.
      Statement filterStatement =
          new StatementBuilder("WHERE customTargetingKeyId = :customTargetingKeyId LIMIT 500")
              .putValue("customTargetingKeyId", customTargetingKeyId).toStatement();

      // Get custom targeting values by statement.
      CustomTargetingValuePage page =
          customTargetingService.getCustomTargetingValuesByStatement(filterStatement);

      if (page.getResults() != null) {
        int i = page.getStartIndex();
        for (CustomTargetingValue customTargetingValue : page.getResults()) {
          System.out.println(i + ") Custom targeting value with ID \""
View Full Code Here

      // Get DfpUser from "~/dfp.properties".
      DfpUser user = new DfpUser();

      // Get the CustomTargetingService.
      CustomTargetingServiceInterface customTargetingService =
          user.getService(DfpService.V201211.CUSTOM_TARGETING_SERVICE);

      // Set the ID of the predefined custom targeting key to get custom
      // targeting values for.
      long customTargetingKeyId = Long.parseLong("INSERT_CUSTOM_TARGETING_KEY_ID_HERE");

      // Create a statement to only select predefined custom targeting values
      // for a given key.
      Statement filterStatement =
          new StatementBuilder("WHERE customTargetingKeyId = :customTargetingKeyId LIMIT 500")
              .putValue("customTargetingKeyId", customTargetingKeyId).toStatement();

      // Get custom targeting values by statement.
      CustomTargetingValuePage page =
          customTargetingService.getCustomTargetingValuesByStatement(filterStatement);

      if (page.getResults() != null) {
        CustomTargetingValue[] customTargetingValues = page.getResults();

        // Update each local custom targeting value object by changing its
        // display name.
        for (CustomTargetingValue customTargetingValue : customTargetingValues) {
          if (customTargetingValue.getDisplayName() == null) {
            customTargetingValue.setDisplayName(customTargetingValue.getName());
          }
          customTargetingValue.setDisplayName(customTargetingValue.getDisplayName()
              + " (Deprecated)");
        }

        // Update the custom targeting values on the server.
        customTargetingValues =
            customTargetingService.updateCustomTargetingValues(customTargetingValues);

        if (customTargetingValues != null) {
          for (CustomTargetingValue customTargetingValue : customTargetingValues) {
            System.out.println("Custom targeting value with ID \""
                + customTargetingValue.getId() + "\", name \"" + customTargetingValue.getName()
View Full Code Here

      // Get DfpUser from "~/dfp.properties".
      DfpUser user = new DfpUser();

      // Get the CustomTargetingService.
      CustomTargetingServiceInterface customTargetingService =
          user.getService(DfpService.V201211.CUSTOM_TARGETING_SERVICE);

      // Sets defaults for page and filter.
      CustomTargetingKeyPage keyPage = new CustomTargetingKeyPage();
      Statement keyFilterStatement = new Statement();
      int keyOffset = 0;

      do {
        // Create a statement to get all custom targeting keys.
        keyFilterStatement.setQuery("LIMIT 500 OFFSET " + keyOffset);

        // Get custom targeting keys by statement.
        keyPage = customTargetingService.getCustomTargetingKeysByStatement(keyFilterStatement);

        if (keyPage.getResults() != null) {
          int i = keyPage.getStartIndex();
          for (CustomTargetingKey key : keyPage.getResults()) {
            System.out.println(i + ") Custom targeting key with ID \"" + key.getId()
                + "\", name \"" + key.getName() + "\", display name \"" + key.getDisplayName()
                + "\", and type \"" + key.getType() + "\" was found.");


            // Sets defaults for page and filter.
            CustomTargetingValuePage valuePage = new CustomTargetingValuePage();
            Statement valueFilterStatement = new Statement();
            int valueOffset = 0;

            do {
              // Create a statement to get all custom targeting values for a
              // custom targeting key (required) by its ID.
              valueFilterStatement.setQuery("WHERE customTargetingKeyId = " + key.getId()
                  + " LIMIT 500 OFFSET " + valueOffset);

              // Get custom targeting values by statement.
              valuePage =
                  customTargetingService.getCustomTargetingValuesByStatement(valueFilterStatement);

              if (valuePage.getResults() != null) {
                int j = valuePage.getStartIndex();
                for (CustomTargetingValue value : valuePage.getResults()) {
                  System.out.println("\t" + j + ") Custom targeting value with ID \""
View Full Code Here

      // Get DfpUser from "~/dfp.properties".
      DfpUser user = new DfpUser();

      // Get the CustomTargetingService.
      CustomTargetingServiceInterface customTargetingService =
          user.getService(DfpService.V201211.CUSTOM_TARGETING_SERVICE);

      // Set the name of the custom targeting key to delete.
      String customTargetingKeyName = "INSERT_CUSTOM_TARGETING_KEY_NAME_HERE";

      // Create statement to only select custom targeting key by the given name.
      String statementText = "WHERE name = :name";
      StatementBuilder statementBuilder = new StatementBuilder("")
          .putValue("name", customTargetingKeyName);

      // Set defaults for page and offset.
      CustomTargetingKeyPage page = new CustomTargetingKeyPage();
      int offset = 0;
      List<Long> customTargetingKeyIds = new ArrayList<Long>();

      do {
        // Create a statement to page through custom targeting keys.
        statementBuilder.setQuery(statementText + " LIMIT 500 OFFSET " + offset);

        // Get custom targeting keys by statement.
        page = customTargetingService.getCustomTargetingKeysByStatement(
            statementBuilder.toStatement());

        if (page.getResults() != null) {
          for (CustomTargetingKey customTargetingKey : page.getResults()) {
            customTargetingKeyIds.add(customTargetingKey.getId());
          }
        }

        offset += 500;
      } while (offset < page.getTotalResultSetSize());

      System.out.println(
          "Number of custom targeting keys to be deleted: " + customTargetingKeyIds.size());

      if (customTargetingKeyIds.size() > 0) {
        // Modify statement for action.
        statementBuilder.setQuery(
            "WHERE id IN (" + StringUtils.join(customTargetingKeyIds, ",") + ")");

        // Create action.
        DeleteCustomTargetingKeys action = new DeleteCustomTargetingKeys();

        // Perform action.
        UpdateResult result = customTargetingService.performCustomTargetingKeyAction(
            action, statementBuilder.toStatement());

        // Display results.
        if (result != null && result.getNumChanges() > 0) {
          System.out.println("Number of custom targeting keys deleted: " + result.getNumChanges());
View Full Code Here

TOP

Related Classes of com.google.api.ads.dfp.v201211.Date

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.