/// <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.v201508.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); } }
private List <long> getAllCustomTargetingKeyIds(DfpUser dfpUser) { List <long> customTargetingKeyIds = new List <long>(); using (CustomTargetingService customTargetingService = (CustomTargetingService)dfpUser.GetService(DfpService.v201708.CustomTargetingService)) { // Create a statement to select custom targeting keys. int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT; StatementBuilder statementBuilder = new StatementBuilder() .OrderBy("id ASC") .Limit(pageSize); // Retrieve a small amount of custom targeting keys at a time, paging through until all // custom targeting keys have been retrieved. int totalResultSetSize = 0; do { CustomTargetingKeyPage page = customTargetingService.getCustomTargetingKeysByStatement( statementBuilder.ToStatement()); // Print out some information for each custom targeting key. if (page.results != null) { totalResultSetSize = page.totalResultSetSize; 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 ); customTargetingKeyIds.Add(customTargetingKey.id); } } statementBuilder.IncreaseOffsetBy(pageSize); } while (statementBuilder.GetOffset() < totalResultSetSize); Console.WriteLine("Number of keys found: {0}", totalResultSetSize); return(customTargetingKeyIds); } }
/// <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.v201411.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 void Run(DfpUser user) { // Get the CustomTargetingService. CustomTargetingService customTargetingService = (CustomTargetingService)user.GetService(DfpService.v201605.CustomTargetingService); // Set the ID of the custom targeting key to update. int customTargetingKeyId = int.Parse(_T("INSERT_CUSTOM_TARGETING_KEY_ID_HERE")); // Create a statement to get the custom targeting key. StatementBuilder statementBuilder = new StatementBuilder() .Where("id = :id") .OrderBy("id ASC") .Limit(1) .AddValue("id", customTargetingKeyId); try { // Get custom targeting keys by statement. CustomTargetingKeyPage page = customTargetingService.getCustomTargetingKeysByStatement( statementBuilder.ToStatement()); CustomTargetingKey customTargetingKey = page.results[0]; // Update each local custom targeting key object by changing its display name. if (customTargetingKey.displayName == null) { customTargetingKey.displayName = customTargetingKey.name; } customTargetingKey.displayName = customTargetingKey.displayName + " (Deprecated)"; // Update the custom targeting keys on the server. CustomTargetingKey[] customTargetingKeys = customTargetingService.updateCustomTargetingKeys( new CustomTargetingKey[] { customTargetingKey }); foreach (CustomTargetingKey updatedCustomTargetingKey in customTargetingKeys) { Console.WriteLine("Custom targeting key with ID \"{0}\", name \"{1}\", and " + "display name \"{2}\" was updated.", updatedCustomTargetingKey.id, updatedCustomTargetingKey.name, updatedCustomTargetingKey.displayName); } } catch (Exception e) { Console.WriteLine("Failed to update display name of custom targeting keys. 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.v201405.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); } }
private static List <long> getPredefinedCustomTargetingKeyIds(DfpUser user) { List <long> customTargetingKeyIds = new List <long>(); CustomTargetingService customTargetingService = (CustomTargetingService)user.GetService(DfpService.v201608.CustomTargetingService); StatementBuilder statementBuilder = new StatementBuilder() .Where("type = :type") .OrderBy("id ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("type", CustomTargetingKeyType.PREDEFINED.ToString()); CustomTargetingKeyPage page = new CustomTargetingKeyPage(); do { page = customTargetingService.getCustomTargetingKeysByStatement( statementBuilder.ToStatement()); if (page.results != null) { // Print out some information for each custom targeting value. int i = page.startIndex; foreach (CustomTargetingKey customTargetingKey in page.results) { Console.WriteLine("{0}) Custom targeting value with ID \"{1}\", name \"{2}\", " + "and display name \"{3}\" was found.", i++, customTargetingKey.id, customTargetingKey.name, customTargetingKey.displayName); customTargetingKeyIds.Add(customTargetingKey.id); } } statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT); } while (statementBuilder.GetOffset() < page.totalResultSetSize); return(customTargetingKeyIds); }
/// <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); } }
/// <summary> /// Run the code example. /// </summary> public void Run(AdManagerUser user) { using (CustomTargetingService customTargetingService = user.GetService <CustomTargetingService>()) { // Create predefined key. CustomTargetingKey genderKey = new CustomTargetingKey(); genderKey.displayName = "gender"; genderKey.name = "g"; genderKey.type = CustomTargetingKeyType.PREDEFINED; // Create predefined key that may be used for content targeting. CustomTargetingKey genreKey = new CustomTargetingKey(); genreKey.displayName = "genre"; genreKey.name = "genre"; genreKey.type = CustomTargetingKeyType.PREDEFINED; // Create free-form key. CustomTargetingKey carModelKey = new CustomTargetingKey(); carModelKey.displayName = "car model"; carModelKey.name = "c"; carModelKey.type = CustomTargetingKeyType.FREEFORM; try { // Create the custom targeting keys on the server. CustomTargetingKey[] keys = customTargetingService.createCustomTargetingKeys( new CustomTargetingKey[] { genderKey, genreKey, carModelKey }); if (keys != null) { foreach (CustomTargetingKey key in keys) { Console.WriteLine( "A custom targeting key with ID \"{0}\", name \"{1}\", and " + "display name \"{2}\" was created.", key.id, key.name, key.displayName); } } else { Console.WriteLine("No keys were created."); } // Create custom targeting value for the predefined gender key. CustomTargetingValue genderMaleValue = new CustomTargetingValue(); genderMaleValue.customTargetingKeyId = keys[0].id; genderMaleValue.displayName = "male"; // Name is set to 1 so that the actual name can be hidden from website // users. genderMaleValue.name = "1"; genderMaleValue.matchType = CustomTargetingValueMatchType.EXACT; CustomTargetingValue genderFemaleValue = new CustomTargetingValue(); genderFemaleValue.customTargetingKeyId = keys[0].id; genderFemaleValue.displayName = "female"; // Name is set to 2 so that the actual name can be hidden from website // users. genderFemaleValue.name = "2"; genderFemaleValue.matchType = CustomTargetingValueMatchType.EXACT; // Create custom targeting value for the predefined genre key. CustomTargetingValue genreComedyValue = new CustomTargetingValue(); genreComedyValue.customTargetingKeyId = keys[1].id; genreComedyValue.displayName = "comedy"; genreComedyValue.name = "comedy"; genreComedyValue.matchType = CustomTargetingValueMatchType.EXACT; CustomTargetingValue genreDramaValue = new CustomTargetingValue(); genreDramaValue.customTargetingKeyId = keys[1].id; genreDramaValue.displayName = "drama"; genreDramaValue.name = "drama"; genreDramaValue.matchType = 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 FreeFormCustomCriteria. CustomTargetingValue carModelHondaCivicValue = new CustomTargetingValue(); carModelHondaCivicValue.customTargetingKeyId = keys[2].id; carModelHondaCivicValue.displayName = "honda civic"; carModelHondaCivicValue.name = "honda civic"; // Setting match type to exact will match exactly "honda civic". carModelHondaCivicValue.matchType = CustomTargetingValueMatchType.EXACT; // Create the custom targeting values on the server. CustomTargetingValue[] returnValues = customTargetingService.createCustomTargetingValues( new CustomTargetingValue[] { genderMaleValue, genderFemaleValue, genreComedyValue, genreDramaValue, carModelHondaCivicValue }); if (returnValues != null) { foreach (CustomTargetingValue value in returnValues) { Console.WriteLine( "A custom targeting value with ID \"{0}\", belonging to key " + "with ID \"{1}\", name \"{2}\", and display name \"{3}\" " + "was created.", value.id, value.customTargetingKeyId, value.name, value.displayName); } } else { Console.WriteLine("No values were created."); } } catch (Exception e) { Console.WriteLine( "Failed to create custom targeting keys and values. Exception " + "says \"{0}\"", e.Message); } } }
/// <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); } }
/// <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 LineItemService. LineItemService lineItemService = (LineItemService)user.GetService( DfpService.v201311.LineItemService); // Get the CustomTargetingService. CustomTargetingService customTargetingService = (CustomTargetingService)user.GetService( DfpService.v201311.CustomTargetingService); long lineItemId = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE")); long[] customCriteriaIds1 = new long[] { long.Parse(_T("INSERT_CUSTOM_TARGETING_KEY_ID_HERE")), long.Parse(_T("INSERT_CUSTOM_TARGETING_VALUE_ID_HERE")) }; long[] customCriteriaIds2 = new long[] { long.Parse(_T("INSERT_CUSTOM_TARGETING_KEY_ID_HERE")), long.Parse(_T("INSERT_CUSTOM_TARGETING_VALUE_ID_HERE")) }; long[] customCriteriaIds3 = new long[] { long.Parse(_T("INSERT_CUSTOM_TARGETING_KEY_ID_HERE")), long.Parse(_T("INSERT_CUSTOM_TARGETING_VALUE_ID_HERE")) }; // Create custom criteria. CustomCriteria customCriteria1 = new CustomCriteria(); customCriteria1.keyId = customCriteriaIds1[0]; customCriteria1.valueIds = new long[] { customCriteriaIds1[1] }; customCriteria1.@operator = CustomCriteriaComparisonOperator.IS; CustomCriteria customCriteria2 = new CustomCriteria(); customCriteria2.keyId = customCriteriaIds2[0]; customCriteria2.valueIds = new long[] { customCriteriaIds2[1] }; customCriteria2.@operator = CustomCriteriaComparisonOperator.IS_NOT; CustomCriteria customCriteria3 = new CustomCriteria(); customCriteria3.keyId = customCriteriaIds3[0]; customCriteria3.valueIds = new long[] { customCriteriaIds3[1] }; customCriteria3.@operator = CustomCriteriaComparisonOperator.IS; // Create the custom criteria set that will resemble: // // (customCriteria1.key == customCriteria1.value OR // (customCriteria2.key != customCriteria2.value AND // customCriteria3.key == customCriteria3.value)) CustomCriteriaSet topCustomCriteriaSet = new CustomCriteriaSet(); topCustomCriteriaSet.logicalOperator = CustomCriteriaSetLogicalOperator.OR; CustomCriteriaSet subCustomCriteriaSet = new CustomCriteriaSet(); subCustomCriteriaSet.logicalOperator = CustomCriteriaSetLogicalOperator.AND; subCustomCriteriaSet.children = new CustomCriteriaNode[] { customCriteria2, customCriteria3 }; topCustomCriteriaSet.children = new CustomCriteriaNode[] { customCriteria1, subCustomCriteriaSet }; try { // Set the custom criteria targeting on the line item. LineItem lineItem = lineItemService.getLineItem(lineItemId); lineItem.targeting.customTargeting = topCustomCriteriaSet; // Update the line items on the server. lineItem = lineItemService.updateLineItem(lineItem); // Display the updated line item. Console.WriteLine("Line item with ID {0} updated with custom criteria targeting \n{1}\n", lineItem.id, getCustomCriteriaSetString(lineItem.targeting.customTargeting, 0)); } catch (Exception ex) { Console.WriteLine("Failed to add custom target criteria. 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 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); } }
/// <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); } }