/// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(AdManagerUser user)
        {
            using (CustomTargetingService customTargetingService =
                       user.GetService <CustomTargetingService>())
            {
                // Set the ID of the predefined custom targeting value to update.
                long customTargetingValueId =
                    long.Parse(_T("INSERT_CUSTOM_TARGETING_VALUE_ID_HERE"));

                // Create a statement to only select predefined custom targeting values
                // for a given key.
                StatementBuilder statementBuilder = new StatementBuilder()
                                                    .Where("id = :customTargetingValueId").OrderBy("id ASC").Limit(1)
                                                    .AddValue("customTargetingValueId", customTargetingValueId);

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

                    CustomTargetingValue customTargetingValue = page.results[0];

                    // Update the local custom targeting value object by changing its display name.
                    if (customTargetingValue.displayName == null)
                    {
                        customTargetingValue.displayName = customTargetingValue.displayName;
                    }

                    customTargetingValue.displayName =
                        customTargetingValue.displayName + " (Deprecated)";

                    // Update the custom targeting values on the server.
                    CustomTargetingValue[] customTargetingValues =
                        customTargetingService.updateCustomTargetingValues(
                            new CustomTargetingValue[]
                    {
                        customTargetingValue
                    });

                    foreach (CustomTargetingValue updatedCustomTargetingValue in
                             customTargetingValues)
                    {
                        Console.WriteLine(
                            "Custom targeting value with ID \"{0}\", name \"{1}\", and " +
                            "display name \"{2}\" was updated.", updatedCustomTargetingValue.id,
                            updatedCustomTargetingValue.name,
                            updatedCustomTargetingValue.displayName);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(
                        "Failed to update display names of custom targeting values. " +
                        "Exception says \"{0}\"", e.Message);
                }
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public void Run(DfpUser dfpUser)
        {
            CustomTargetingService customTargetingService =
                (CustomTargetingService)dfpUser.GetService(DfpService.v201608.CustomTargetingService);

            // Create a statement to select custom targeting values for a custom
            // targeting key.
            int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT;
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("customTargetingKeyId = :customTargetingKeyId")
                                                .OrderBy("id ASC")
                                                .Limit(pageSize);

            List <long> customTargetingKeyIds = getPredefinedCustomTargetingKeyIds(dfpUser);

            // For each key, retrieve all its values.
            int totalValueCounter = 0;

            foreach (long customTargetingKeyId in customTargetingKeyIds)
            {
                // Set the custom targeting key ID to select from.
                statementBuilder.AddValue("customTargetingKeyId", customTargetingKeyId);

                // Retrieve a small amount of custom targeting values at a time, paging through until all
                // custom targeting values have been retrieved.
                int totalResultSetSize = 0;
                statementBuilder.Offset(0);
                do
                {
                    CustomTargetingValuePage page =
                        customTargetingService.getCustomTargetingValuesByStatement(
                            statementBuilder.ToStatement());

                    // Print out some information for each custom targeting value.
                    if (page.results != null)
                    {
                        totalResultSetSize = page.totalResultSetSize;
                        foreach (CustomTargetingValue customTargetingValue in page.results)
                        {
                            Console.WriteLine(
                                "{0}) Custom targeting value with ID {1}, " +
                                "name \"{2}\", " +
                                "display name \"{3}\", " +
                                "and custom targeting key ID {4} was found.",
                                totalValueCounter++,
                                customTargetingValue.id,
                                customTargetingValue.name,
                                customTargetingValue.displayName,
                                customTargetingValue.customTargetingKeyId
                                );
                        }
                    }

                    statementBuilder.IncreaseOffsetBy(pageSize);
                } while (statementBuilder.GetOffset() < totalResultSetSize);
            }

            Console.WriteLine("Number of results found: {0}", totalValueCounter);
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            CustomTargetingService customTargetingService =
                (CustomTargetingService)user.GetService(DfpService.v201608.CustomTargetingService);

            List <long> customTargetingKeyIds = getPredefinedCustomTargetingKeyIds(user);

            // Create a statement to select custom targeting values.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("customTargetingKeyId = :customTargetingKeyId")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

            foreach (long customTargetingKeyId in customTargetingKeyIds)
            {
                // Set the custom targeting key ID to select from.
                statementBuilder.AddValue("customTargetingKeyId", customTargetingKeyId);

                // Retrieve a small amount of custom targeting values at a time, paging through
                // until all custom targeting values have been retrieved.
                CustomTargetingValuePage page = new CustomTargetingValuePage();
                try {
                    do
                    {
                        page = customTargetingService.getCustomTargetingValuesByStatement(
                            statementBuilder.ToStatement());

                        if (page.results != null)
                        {
                            // Print out some information for each custom targeting value.
                            int i = page.startIndex;
                            foreach (CustomTargetingValue customTargetingValue in page.results)
                            {
                                Console.WriteLine("{0}) Custom targeting value with ID \"{1}\", name \"{2}\", "
                                                  + "display name \"{3}\", and custom targeting key ID \"{4}\" was found.",
                                                  i++,
                                                  customTargetingValue.id,
                                                  customTargetingValue.name,
                                                  customTargetingValue.displayName,
                                                  customTargetingValue.customTargetingKeyId);
                            }
                        }

                        statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
                    } while (statementBuilder.GetOffset() < page.totalResultSetSize);

                    Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
                } catch (Exception e) {
                    Console.WriteLine("Failed to get custom targeting values. Exception says \"{0}\"",
                                      e.Message);
                }
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the CustomTargetingService.
            CustomTargetingService customTargetingService =
                (CustomTargetingService)user.GetService(DfpService.v201403.CustomTargetingService);

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

            // Create a statement to only select custom targeting values for a given
            // key.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("customTargetingKeyId = :customTargetingKeyId")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("customTargetingKeyId", customTargetingKeyId);

            // Set default for page.
            CustomTargetingValuePage page = new CustomTargetingValuePage();

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

                    if (page.results != null)
                    {
                        int i = page.startIndex;
                        foreach (CustomTargetingValue customTargetingValue in page.results)
                        {
                            Console.WriteLine("{0}) Custom targeting value with ID \"{1}\", name \"{2}\", and " +
                                              "display name \"{3}\" was found.", i, customTargetingValue.id,
                                              customTargetingValue.name, customTargetingValue.displayName);
                            i++;
                        }
                    }

                    statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
                } while (statementBuilder.GetOffset() < page.totalResultSetSize);
                Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
            } catch (Exception ex) {
                Console.WriteLine("Failed to get custom targeting values. Exception " +
                                  "says \"{0}\"", ex.Message);
            }
        }
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Get the CustomTargetingService.
      CustomTargetingService customTargetingService =
          (CustomTargetingService) user.GetService(DfpService.v201508.CustomTargetingService);

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

      // Create a statement to only select custom targeting values for a given
      // key.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("customTargetingKeyId = :customTargetingKeyId")
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
         .AddValue("customTargetingKeyId", customTargetingKeyId);

      // Set default for page.
      CustomTargetingValuePage page = new CustomTargetingValuePage();

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

          if (page.results != null) {
            int i = page.startIndex;
            foreach (CustomTargetingValue customTargetingValue in page.results) {
              Console.WriteLine("{0}) Custom targeting value with ID \"{1}\", name \"{2}\", and " +
                  "display name \"{3}\" was found.", i, customTargetingValue.id,
                  customTargetingValue.name, customTargetingValue.displayName);
              i++;
            }
          }

          statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while (statementBuilder.GetOffset() < page.totalResultSetSize);
        Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
      } catch (Exception e) {
        Console.WriteLine("Failed to get custom targeting values. Exception " +
            "says \"{0}\"", e.Message);
      }
    }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the CreativeService.
            CustomTargetingService customTargetingService =
                (CustomTargetingService)user.GetService(DfpService.v201311.CustomTargetingService);

            // Set the ID of the custom targeting key to get custom targeting values
            // for.
            long customTargetingKeyId = long.Parse(_T("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")
                .AddValue("customTargetingKeyId", customTargetingKeyId).ToStatement();

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

                if (page.results != null)
                {
                    int i = page.startIndex;
                    foreach (CustomTargetingValue customTargetingValue in page.results)
                    {
                        Console.WriteLine("{0}) Custom targeting value with ID \"{1}\", name \"{2}\", and " +
                                          "display name \"{3}\" was found.", i, customTargetingValue.id,
                                          customTargetingValue.name, customTargetingValue.displayName);
                        i++;
                    }
                }

                Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
            } catch (Exception ex) {
                Console.WriteLine("Failed to get custom targeting values. Exception " +
                                  "says \"{0}\"", ex.Message);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            // Get the CustomTargetingService.
            CustomTargetingService customTargetingService =
                (CustomTargetingService)user.GetService(DfpService.v201605.CustomTargetingService);

            // Create a statement to get all custom targeting keys.
            StatementBuilder keyStatementBuilder = new StatementBuilder()
                                                   .OrderBy("id ASC")
                                                   .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

            // Set default for page.
            CustomTargetingKeyPage keyPage = new CustomTargetingKeyPage();

            try {
                do
                {
                    // Get custom targeting keys by statement.
                    keyPage = customTargetingService.getCustomTargetingKeysByStatement(
                        keyStatementBuilder.ToStatement());

                    if (keyPage.results != null)
                    {
                        int i = keyPage.startIndex;
                        foreach (CustomTargetingKey key in keyPage.results)
                        {
                            Console.WriteLine("{0}) Custom targeting key with ID \"{1}\", name \"{2}\", " +
                                              "display name \"{3}\", and type \"{4}\" was found.", i, key.id, key.name,
                                              key.displayName, key.type);

                            // Create a statement to get all custom targeting values for a
                            // custom targeting key (required) by its ID.
                            StatementBuilder valueStatementBuilder = new StatementBuilder()
                                                                     .Where("customTargetingKeyId = :customTargetingKeyId")
                                                                     .OrderBy("id ASC")
                                                                     .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                                     .AddValue("customTargetingKeyId", key.id);

                            // Set default for page.
                            CustomTargetingValuePage valuePage = new CustomTargetingValuePage();

                            do
                            {
                                // Get custom targeting values by statement.
                                valuePage = customTargetingService.getCustomTargetingValuesByStatement(
                                    valueStatementBuilder.ToStatement());

                                if (valuePage.results != null)
                                {
                                    int j = valuePage.startIndex;
                                    foreach (CustomTargetingValue value in valuePage.results)
                                    {
                                        Console.WriteLine("\t{0}) Custom targeting value with ID \"{1}\", name " +
                                                          "\"{2}\", and display name \"{3}\" was found.", j, value.id, value.name,
                                                          value.displayName);
                                        j++;
                                    }
                                }
                                valueStatementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
                            } while (valueStatementBuilder.GetOffset() < valuePage.totalResultSetSize);
                            i++;
                        }
                    }
                    keyStatementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
                } while (keyStatementBuilder.GetOffset() < keyPage.totalResultSetSize);
                Console.WriteLine("Number of results found: {0}", keyPage.totalResultSetSize);
            } catch (Exception e) {
                Console.WriteLine("Failed to get custom targeting keys and the values. Exception " +
                                  "says \"{0}\"", e.Message);
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the ContentService.
            ContentService contentService =
                (ContentService)user.GetService(DfpService.v201403.ContentService);

            // Get the NetworkService.
            NetworkService networkService = (NetworkService)user.GetService(
                DfpService.v201403.NetworkService);

            // Get the CustomTargetingService.
            CustomTargetingService customTargetingService = (CustomTargetingService)user.GetService(
                DfpService.v201403.CustomTargetingService);

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

                // Create a statement to select the categories matching the name comedy.
                Statement categoryFilterStatement = new StatementBuilder()
                                                    .Where("customTargetingKeyId = :contentBrowseCustomTargetingKeyId " +
                                                           " and name = :category")
                                                    .OrderBy("id ASC")
                                                    .Limit(1)
                                                    .AddValue("contentBrowseCustomTargetingKeyId", contentBrowseCustomTargetingKeyId)
                                                    .AddValue("category", "comedy")
                                                    .ToStatement();

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

                if (customTargetingValuePage.results != null)
                {
                    // Get the custom targeting value ID for the comedy category.
                    long categoryCustomTargetingValueId = customTargetingValuePage.results[0].id;

                    // Create a statement to get all active content.
                    StatementBuilder statementBuilder = new StatementBuilder()
                                                        .Where("status = :status")
                                                        .OrderBy("id ASC")
                                                        .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                        .AddValue("status", "ACTIVE");

                    // Set defaults for page and filterStatement.
                    ContentPage page = new ContentPage();

                    do
                    {
                        // Get content by statement.
                        page = contentService.getContentByStatementAndCustomTargetingValue(
                            statementBuilder.ToStatement(), categoryCustomTargetingValueId);

                        if (page.results != null)
                        {
                            int i = page.startIndex;
                            foreach (Content content in page.results)
                            {
                                Console.WriteLine("{0})  Content with ID \"{1}\", name \"{2}\", and status " +
                                                  "\"{3}\" was found.", i, content.id, content.name, content.status);
                                i++;
                            }
                        }
                        statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
                    } while (statementBuilder.GetOffset() < page.totalResultSetSize);

                    Console.WriteLine("Number of results found: " + page.totalResultSetSize);
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to get content by category. Exception says \"{0}\"", ex.Message);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the ContentService.
            ContentService contentService =
                (ContentService)user.GetService(DfpService.v201311.ContentService);

            // Get the NetworkService.
            NetworkService networkService = (NetworkService)user.GetService(
                DfpService.v201311.NetworkService);

            // Get the CustomTargetingService.
            CustomTargetingService customTargetingService = (CustomTargetingService)user.GetService(
                DfpService.v201311.CustomTargetingService);

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

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

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

                if (customTargetingValuePage.results != null)
                {
                    // Get the custom targeting value ID for the comedy category.
                    long categoryCustomTargetingValueId = customTargetingValuePage.results[0].id;

                    // Set defaults for page and filterStatement.
                    ContentPage page            = new ContentPage();
                    Statement   filterStatement = new Statement();
                    int         offset          = 0;

                    do
                    {
                        // Create a statement to get all active content.
                        filterStatement.query = "WHERE status = 'ACTIVE' LIMIT 500 OFFSET " + offset.ToString();

                        // Get content by statement.
                        page = contentService.getContentByStatementAndCustomTargetingValue(filterStatement,
                                                                                           categoryCustomTargetingValueId);

                        if (page.results != null)
                        {
                            int i = page.startIndex;
                            foreach (Content content in page.results)
                            {
                                Console.WriteLine("{0})  Content with ID \"{1}\", name \"{2}\", and status " +
                                                  "\"{3}\" was found.", i, content.id, content.name, content.status);
                                i++;
                            }
                        }
                        offset += 500;
                    } while (offset < page.totalResultSetSize);

                    Console.WriteLine("Number of results found: " + page.totalResultSetSize);
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to get content by category. Exception says \"{0}\"", ex.Message);
            }
        }
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Get the CustomTargetingService.
      CustomTargetingService customTargetingService =
          (CustomTargetingService) user.GetService(DfpService.v201511.CustomTargetingService);

      // Create a statement to get all custom targeting keys.
      StatementBuilder keyStatementBuilder = new StatementBuilder()
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

      // Set default for page.
      CustomTargetingKeyPage keyPage = new CustomTargetingKeyPage();

      try {
        do {
          // Get custom targeting keys by statement.
          keyPage = customTargetingService.getCustomTargetingKeysByStatement(
              keyStatementBuilder.ToStatement());

          if (keyPage.results != null) {
            int i = keyPage.startIndex;
            foreach (CustomTargetingKey key in keyPage.results) {
              Console.WriteLine("{0}) Custom targeting key with ID \"{1}\", name \"{2}\", " +
                  "display name \"{3}\", and type \"{4}\" was found.", i, key.id, key.name,
                  key.displayName, key.type);

              // Create a statement to get all custom targeting values for a
              // custom targeting key (required) by its ID.
              StatementBuilder valueStatementBuilder = new StatementBuilder()
                  .Where("customTargetingKeyId = :customTargetingKeyId")
                  .OrderBy("id ASC")
                  .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                  .AddValue("customTargetingKeyId", key.id);

              // Set default for page.
              CustomTargetingValuePage valuePage = new CustomTargetingValuePage();

              do {
                // Get custom targeting values by statement.
                valuePage = customTargetingService.getCustomTargetingValuesByStatement(
                    valueStatementBuilder.ToStatement());

                if (valuePage.results != null) {
                  int j = valuePage.startIndex;
                  foreach (CustomTargetingValue value in valuePage.results) {
                    Console.WriteLine("\t{0}) Custom targeting value with ID \"{1}\", name " +
                        "\"{2}\", and display name \"{3}\" was found.", j, value.id, value.name,
                        value.displayName);
                    j++;
                  }
                }
                valueStatementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
              } while (valueStatementBuilder.GetOffset() < valuePage.totalResultSetSize);
              i++;
            }
          }
          keyStatementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while (keyStatementBuilder.GetOffset() < keyPage.totalResultSetSize);
        Console.WriteLine("Number of results found: {0}", keyPage.totalResultSetSize);
      } catch (Exception e) {
        Console.WriteLine("Failed to get custom targeting keys and the values. Exception " +
            "says \"{0}\"", e.Message);
      }
    }
Esempio n. 11
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the CreativeService.
            CustomTargetingService customTargetingService =
                (CustomTargetingService)user.GetService(DfpService.v201311.CustomTargetingService);

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

            try {
                do
                {
                    // Create a statement to get all custom targeting keys.
                    keyFilterStatement.query = "LIMIT 500 OFFSET " + keyOffset;

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

                    if (keyPage.results != null)
                    {
                        int i = keyPage.startIndex;
                        foreach (CustomTargetingKey key in keyPage.results)
                        {
                            Console.WriteLine("{0}) Custom targeting key with ID \"{1}\", name \"{2}\", " +
                                              "display name \"{3}\", and type \"{4}\" was found.", i, key.id, key.name,
                                              key.displayName, key.type);


                            // 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.query = string.Format("WHERE customTargetingKeyId = {0} " +
                                                                           "LIMIT 500 OFFSET {1}", key.id, valueOffset);

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

                                if (valuePage.results != null)
                                {
                                    int j = valuePage.startIndex;
                                    foreach (CustomTargetingValue value in valuePage.results)
                                    {
                                        Console.WriteLine("\t{0}) Custom targeting value with ID \"{1}\", name " +
                                                          "\"{2}\", and display name \"{3}\" was found.", j, value.id, value.name,
                                                          value.displayName);
                                        j++;
                                    }
                                }
                                valueOffset += 500;
                            } while (valuePage.results != null && valuePage.results.Length == 500);
                            i++;
                        }
                    }
                    keyOffset += 500;
                } while (keyPage.results != null && keyPage.results.Length == 500);
                Console.WriteLine("Number of results found: {0}", keyPage.totalResultSetSize);
            } catch (Exception ex) {
                Console.WriteLine("Failed to get custom targeting keys and the values. Exception " +
                                  "says \"{0}\"", ex.Message);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the CreativeService.
            CustomTargetingService customTargetingService =
                (CustomTargetingService)user.GetService(DfpService.v201311.CustomTargetingService);

            // Set the ID of the predefined custom targeting key to get custom
            // targeting values for.
            long customTargetingKeyId = long.Parse(_T("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")
                .AddValue("customTargetingKeyId", customTargetingKeyId).ToStatement();

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

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

                    // Update each local custom targeting value object by changing its
                    // display name.
                    foreach (CustomTargetingValue customTargetingValue in customTargetingValues)
                    {
                        if (customTargetingValue.displayName == null)
                        {
                            customTargetingValue.displayName = customTargetingValue.displayName;
                        }
                        customTargetingValue.displayName = customTargetingValue.displayName + " (Deprecated)";
                    }

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

                    if (customTargetingValues != null)
                    {
                        foreach (CustomTargetingValue customTargetingValue in customTargetingValues)
                        {
                            Console.WriteLine("Custom targeting value with ID \"{0}\", name \"{1}\", and " +
                                              "display name \"{2}\" was updated.", customTargetingValue.id,
                                              customTargetingValue.name, customTargetingValue.displayName);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No custom targeting values updated.");
                    }
                }
                else
                {
                    Console.WriteLine("No custom targeting values found to update.");
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to update display names of custom targeting values. Exception " +
                                  "says \"{0}\"", ex.Message);
            }
        }