/// <summary> /// Run the code example. /// </summary> public void Run(AdManagerUser user) { using (CustomTargetingService customTargetingService = user.GetService <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 = getAllCustomTargetingKeyIds(user); // 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); } } }