Examples of CustomTargetingServiceInterface


Examples of com.google.api.ads.dfp.axis.v201302.CustomTargetingServiceInterface

*/
public class GetPredefinedCustomTargetingKeysAndValues {

  public static void runExample(DfpServices dfpServices, DfpSession session) throws Exception {
    // Get the CustomTargetingService.
    CustomTargetingServiceInterface customTargetingService =
        dfpServices.get(session, CustomTargetingServiceInterface.class);

    // Get all predefined custom targeting keys.
    List<Long> customTargetingKeyIds = getPredefinedCustomTargetingKeyIds(dfpServices, session);

    // Create a statement to get all custom targeting values for a custom
    // targeting key.
    StatementBuilder statementBuilder = new StatementBuilder()
        .where("customTargetingKeyId = :customTargetingKeyId")
        .orderBy("id ASC")
        .limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

    int totalResultsCounter = 0;

    for (Long customTargetingKeyId : customTargetingKeyIds) {
      // Set the custom targeting key ID to select from.
      statementBuilder.withBindVariableValue("customTargetingKeyId", customTargetingKeyId);

      // Default for total result set size and offset.
      int totalResultSetSize = 0;
      statementBuilder.offset(0);

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

        if (page.getResults() != null) {
          totalResultSetSize = page.getTotalResultSetSize();
          for (CustomTargetingValue customTargetingValue : page.getResults()) {
View Full Code Here

Examples of com.google.api.ads.dfp.axis.v201306.CustomTargetingServiceInterface

*/
public class GetAllCustomTargetingKeysAndValues {

  public static void runExample(DfpServices dfpServices, DfpSession session) throws Exception {
    // Get the CustomTargetingService.
    CustomTargetingServiceInterface customTargetingService =
        dfpServices.get(session, CustomTargetingServiceInterface.class);

    // Get all custom targeting keys.
    List<Long> customTargetingKeyIds = getAllCustomTargetingKeyIds(dfpServices, session);

    // Create a statement to get all custom targeting values for a custom
    // targeting key.
    StatementBuilder statementBuilder = new StatementBuilder()
        .where("customTargetingKeyId = :customTargetingKeyId")
        .orderBy("id ASC")
        .limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

    int totalResultsCounter = 0;

    for (Long customTargetingKeyId : customTargetingKeyIds) {
      // Set the custom targeting key ID to select from.
      statementBuilder.withBindVariableValue("customTargetingKeyId", customTargetingKeyId);

      // Default for total result set size and offset.
      int totalResultSetSize = 0;
      statementBuilder.offset(0);

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

        if (page.getResults() != null) {
          totalResultSetSize = page.getTotalResultSetSize();
          for (CustomTargetingValue customTargetingValue : page.getResults()) {
View Full Code Here

Examples of com.google.api.ads.dfp.axis.v201308.CustomTargetingServiceInterface

*/
public class GetAllCustomTargetingKeysAndValues {

  public static void runExample(DfpServices dfpServices, DfpSession session) throws Exception {
    // Get the CustomTargetingService.
    CustomTargetingServiceInterface customTargetingService =
        dfpServices.get(session, CustomTargetingServiceInterface.class);

    // Get all custom targeting keys.
    List<Long> customTargetingKeyIds = getAllCustomTargetingKeyIds(dfpServices, session);

    // Create a statement to get all custom targeting values for a custom
    // targeting key.
    StatementBuilder statementBuilder = new StatementBuilder()
        .where("customTargetingKeyId = :customTargetingKeyId")
        .orderBy("id ASC")
        .limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

    int totalResultsCounter = 0;

    for (Long customTargetingKeyId : customTargetingKeyIds) {
      // Set the custom targeting key ID to select from.
      statementBuilder.withBindVariableValue("customTargetingKeyId", customTargetingKeyId);

      // Default for total result set size and offset.
      int totalResultSetSize = 0;
      statementBuilder.offset(0);

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

        if (page.getResults() != null) {
          totalResultSetSize = page.getTotalResultSetSize();
          for (CustomTargetingValue customTargetingValue : page.getResults()) {
View Full Code Here

Examples of com.google.api.ads.dfp.axis.v201311.CustomTargetingServiceInterface

*/
public class GetAllCustomTargetingKeysAndValues {

  public static void runExample(DfpServices dfpServices, DfpSession session) throws Exception {
    // Get the CustomTargetingService.
    CustomTargetingServiceInterface customTargetingService =
        dfpServices.get(session, CustomTargetingServiceInterface.class);

    // Get all custom targeting keys.
    List<Long> customTargetingKeyIds = getAllCustomTargetingKeyIds(dfpServices, session);

    // Create a statement to get all custom targeting values for a custom
    // targeting key.
    StatementBuilder statementBuilder = new StatementBuilder()
        .where("customTargetingKeyId = :customTargetingKeyId")
        .orderBy("id ASC")
        .limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

    int totalResultsCounter = 0;

    for (Long customTargetingKeyId : customTargetingKeyIds) {
      // Set the custom targeting key ID to select from.
      statementBuilder.withBindVariableValue("customTargetingKeyId", customTargetingKeyId);

      // Default for total result set size and offset.
      int totalResultSetSize = 0;
      statementBuilder.offset(0);

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

        if (page.getResults() != null) {
          totalResultSetSize = page.getTotalResultSetSize();
          for (CustomTargetingValue customTargetingValue : page.getResults()) {
View Full Code Here

Examples of com.google.api.ads.dfp.v201208.CustomTargetingServiceInterface

      // Get the LineItemService.
      LineItemServiceInterface lineItemService =
          user.getService(DfpService.V201208.LINEITEM_SERVICE);

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

      Long lineItemId = Long.parseLong("INSERT_LINE_ITEM_ID_HERE");
      Long[] customCriteriaIds1 =
          new Long[] {Long.parseLong("INSERT_CUSTOM_TARGETING_KEY_ID_HERE"),
View Full Code Here

Examples of com.google.api.ads.dfp.v201208.CustomTargetingServiceInterface

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

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

      // Create predefined key.
      CustomTargetingKey genderKey = new CustomTargetingKey();
      genderKey.setDisplayName("gender");
      genderKey.setName("g");
      genderKey.setType(CustomTargetingKeyType.PREDEFINED);

      // Create predefined key that may be used for content targeting.
      CustomTargetingKey genreKey = new CustomTargetingKey();
      genreKey.setDisplayName("genre");
      genreKey.setName("genre");
      genreKey.setType(CustomTargetingKeyType.PREDEFINED);

      // Create free-form key.
      CustomTargetingKey carModelKey = new CustomTargetingKey();
      carModelKey.setDisplayName("car model");
      carModelKey.setName("c");
      carModelKey.setType(CustomTargetingKeyType.FREEFORM);

      // Create the custom targeting keys on the server.
      CustomTargetingKey[] keys = customTargetingService.createCustomTargetingKeys(
          new CustomTargetingKey[] {genderKey, genreKey, carModelKey});

      if (keys != null) {
        for (CustomTargetingKey key : keys) {
          System.out.println("A custom targeting key with ID \"" + key.getId()
              + "\", name \"" + key.getName() + "\", and display name \""
              + key.getDisplayName() + "\" was created.");
        }
      } else {
        System.out.println("No keys were created.");
      }

      // Create custom targeting value for the predefined gender key.
      CustomTargetingValue genderMaleValue = new CustomTargetingValue();
      genderMaleValue.setCustomTargetingKeyId(keys[0].getId());
      genderMaleValue.setDisplayName("male");
      // Name is set to 1 so that the actual name can be hidden from website
      // users.
      genderMaleValue.setName("1");
      genderMaleValue.setMatchType(CustomTargetingValueMatchType.EXACT);

      CustomTargetingValue genderFemaleValue = new CustomTargetingValue();
      genderFemaleValue.setCustomTargetingKeyId(keys[0].getId());
      genderFemaleValue.setDisplayName("female");
      // Name is set to 2 so that the actual name can be hidden from website
      // users.
      genderFemaleValue.setName("2");
      genderFemaleValue.setMatchType(CustomTargetingValueMatchType.EXACT);

      // Create custom targeting value for the predefined genre key.
      CustomTargetingValue genreComedyValue = new CustomTargetingValue();
      genreComedyValue.setCustomTargetingKeyId(keys[1].getId());
      genreComedyValue.setDisplayName("comedy");
      genreComedyValue.setName("comedy");
      genreComedyValue.setMatchType(CustomTargetingValueMatchType.EXACT);

      CustomTargetingValue genreDramaValue = new CustomTargetingValue();
      genreDramaValue.setCustomTargetingKeyId(keys[1].getId());
      genreDramaValue.setDisplayName("drama");
      genreDramaValue.setName("drama");
      genreDramaValue.setMatchType(CustomTargetingValueMatchType.EXACT);

      // Create custom targeting value for the free-form age key. These are
      // values that would be suggested in the UI or can be used when targeting
      // with a {@link FreeFormCustomCriteria}.
      CustomTargetingValue carModelHondaCivicValue = new CustomTargetingValue();
      carModelHondaCivicValue.setCustomTargetingKeyId(keys[2].getId());
      carModelHondaCivicValue.setDisplayName("honda civic");
      carModelHondaCivicValue.setName("honda civic");
      // Setting match type to exact will match exactly "honda civic".
      carModelHondaCivicValue.setMatchType(CustomTargetingValueMatchType.EXACT);

      // Create the custom targeting values on the server.
      CustomTargetingValue[] returnValues =
          customTargetingService.createCustomTargetingValues(new CustomTargetingValue[] {
              genderMaleValue, genderFemaleValue, genreComedyValue, genreDramaValue,
              carModelHondaCivicValue});

      if (returnValues != null) {
        for (CustomTargetingValue value : returnValues) {
View Full Code Here

Examples of com.google.api.ads.dfp.v201208.CustomTargetingServiceInterface

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

      // Get the CustomTargetingService.
      CustomTargetingServiceInterface customTargetingService =
          user.getService(DfpService.V201208.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

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

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

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

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

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

      // 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
TOP
Copyright © 2018 www.massapi.com. 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.