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

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


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

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

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

      } 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,
View Full Code Here

          " 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.
      ContentPage page = new ContentPage();
      Statement filterStatement = new Statement();
      int offset = 0;
View Full Code Here

      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) {
View Full Code Here

      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 \""
              + customTargetingValue.getId() + "\", name \"" + customTargetingValue.getName()
              + "\", and display name \"" + customTargetingValue.getDisplayName()
              + "\" was found.");
          i++;
        }
      }

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

      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) {
View Full Code Here

                + "\", 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;
View Full Code Here

   */
  public static Date fromDate(java.util.Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);

    Date dfpDate = new Date();
    dfpDate.setYear(calendar.get(Calendar.YEAR));
    dfpDate.setMonth(calendar.get(Calendar.MONTH) + 1);
    dfpDate.setDay(calendar.get(Calendar.DAY_OF_MONTH));

    return dfpDate;
  }
View Full Code Here

TOP

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

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.