/// <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.v201408.CustomTargetingService); // Create a statement to only select predefined custom targeting keys. StatementBuilder statementBuilder = new StatementBuilder() .Where("type = :type") .OrderBy("id ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("type", CustomTargetingKeyType.PREDEFINED.ToString()); // Set default for page. CustomTargetingKeyPage page = new CustomTargetingKeyPage(); try { do { // Get custom targeting keys by statement. page = customTargetingService.getCustomTargetingKeysByStatement( statementBuilder.ToStatement()); if (page.results != null) { int i = page.startIndex; foreach (CustomTargetingKey customTargetingKey in page.results) { Console.WriteLine("{0}) Custom targeting key with ID \"{1}\", name \"{2}\", and " + "display name \"{3}\" was found.", i, customTargetingKey.id, customTargetingKey.name, customTargetingKey.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 predefined custom targeting keys. 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.v201408.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 ex) { Console.WriteLine("Failed to get custom targeting keys and the values. Exception " + "says \"{0}\"", ex.Message); } }