/// <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 SuggestedAdUnitService. SuggestedAdUnitService suggestedAdUnitService = (SuggestedAdUnitService)user.GetService( DfpService.v201311.SuggestedAdUnitService); // Create statement to select all suggested ad units with 50 or more // requests. string statementText = "WHERE numRequests >= 50"; Statement filterStatement = new StatementBuilder(statementText).ToStatement(); try { // Get suggested ad units by statement. SuggestedAdUnitPage page = suggestedAdUnitService.getSuggestedAdUnitsByStatement(filterStatement); int i = 0; if (page != null && page.results != null) { foreach (SuggestedAdUnit suggestedAdUnit in page.results) { Console.WriteLine("{0}) Suggested ad unit with ID \"{1}\", and \"{2}\" will be " + "approved.", i, suggestedAdUnit.id, suggestedAdUnit.numRequests); i++; } Console.WriteLine("Number of suggested ad units to be approved: " + page.totalResultSetSize); // Create action. ApproveSuggestedAdUnit action = new ApproveSuggestedAdUnit(); // Perform action. SuggestedAdUnitUpdateResult result = suggestedAdUnitService.performSuggestedAdUnitAction( action, filterStatement); // Display results. if (result != null && result.numChanges > 0) { Console.WriteLine("Number of suggested ad units approved: " + result.numChanges); } else { Console.WriteLine("No suggested ad units were approved."); } } else { Console.WriteLine("No suggested ad units were approved."); } } catch (Exception ex) { Console.WriteLine("Failed to approve suggested ad units. 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 SuggestedAdUnitService. SuggestedAdUnitService suggestedAdUnitService = (SuggestedAdUnitService) user.GetService( DfpService.v201302.SuggestedAdUnitService); // Create statement to select all suggested ad units with 50 or more // requests. string statementText = "WHERE numRequests >= 50"; Statement filterStatement = new StatementBuilder(statementText).ToStatement(); try { // Get suggested ad units by statement. SuggestedAdUnitPage page = suggestedAdUnitService.getSuggestedAdUnitsByStatement(filterStatement); int i = 0; if (page != null && page.results != null) { foreach (SuggestedAdUnit suggestedAdUnit in page.results) { Console.WriteLine("{0}) Suggested ad unit with ID \"{1}\", and \"{2}\" will be " + "approved.", i, suggestedAdUnit.id, suggestedAdUnit.numRequests); i++; } Console.WriteLine("Number of suggested ad units to be approved: " + page.totalResultSetSize); // Create action. ApproveSuggestedAdUnit action = new ApproveSuggestedAdUnit(); // Perform action. SuggestedAdUnitUpdateResult result = suggestedAdUnitService.performSuggestedAdUnitAction( action, filterStatement); // Display results. if (result != null && result.numChanges > 0) { Console.WriteLine("Number of suggested ad units approved: " + result.numChanges); } else { Console.WriteLine("No suggested ad units were approved."); } } else { Console.WriteLine("No suggested ad units were approved."); } } catch (Exception ex) { Console.WriteLine("Failed to approve suggested ad units. 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 SuggestedAdUnitService. SuggestedAdUnitService suggestedAdUnitService = (SuggestedAdUnitService) user.GetService( DfpService.v201511.SuggestedAdUnitService); // Set the number of requests for suggested ad units greater than which to approve. long NUMBER_OF_REQUESTS = 50L; // Create statement to select all suggested ad units that are highly requested. StatementBuilder statementBuilder = new StatementBuilder() .Where("numRequests > :numRequests") .OrderBy("id ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("numRequests", NUMBER_OF_REQUESTS); // Set default for page. SuggestedAdUnitPage page = new SuggestedAdUnitPage(); try { do { // Get suggested ad units by statement. page = suggestedAdUnitService.getSuggestedAdUnitsByStatement( statementBuilder.ToStatement()); int i = 0; if (page != null && page.results != null) { foreach (SuggestedAdUnit suggestedAdUnit in page.results) { Console.WriteLine("{0}) Suggested ad unit with ID \"{1}\", and \"{2}\" will be " + "approved.", i, suggestedAdUnit.id, suggestedAdUnit.numRequests); i++; } } statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT); } while(statementBuilder.GetOffset() < page.totalResultSetSize); Console.WriteLine("Number of suggested ad units to be approved: " + page.totalResultSetSize); // Modify statement for action. statementBuilder.RemoveLimitAndOffset(); // Create action. ApproveSuggestedAdUnit action = new ApproveSuggestedAdUnit(); // Perform action. SuggestedAdUnitUpdateResult result = suggestedAdUnitService.performSuggestedAdUnitAction( action, statementBuilder.ToStatement()); // Display results. if (result != null && result.numChanges > 0) { Console.WriteLine("Number of new ad units created: " + result.newAdUnitIds.Length); } else { Console.WriteLine("No suggested ad units were approved."); } } catch (Exception e) { Console.WriteLine("Failed to approve suggested ad units. 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 SuggestedAdUnitService. SuggestedAdUnitService suggestedAdUnitService = (SuggestedAdUnitService)user.GetService( DfpService.v201511.SuggestedAdUnitService); // Set the number of requests for suggested ad units greater than which to approve. long NUMBER_OF_REQUESTS = 50L; // Create statement to select all suggested ad units that are highly requested. StatementBuilder statementBuilder = new StatementBuilder() .Where("numRequests > :numRequests") .OrderBy("id ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("numRequests", NUMBER_OF_REQUESTS); // Set default for page. SuggestedAdUnitPage page = new SuggestedAdUnitPage(); try { do { // Get suggested ad units by statement. page = suggestedAdUnitService.getSuggestedAdUnitsByStatement( statementBuilder.ToStatement()); int i = 0; if (page != null && page.results != null) { foreach (SuggestedAdUnit suggestedAdUnit in page.results) { Console.WriteLine("{0}) Suggested ad unit with ID \"{1}\", and \"{2}\" will be " + "approved.", i, suggestedAdUnit.id, suggestedAdUnit.numRequests); i++; } } statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT); } while(statementBuilder.GetOffset() < page.totalResultSetSize); Console.WriteLine("Number of suggested ad units to be approved: " + page.totalResultSetSize); // Modify statement for action. statementBuilder.RemoveLimitAndOffset(); // Create action. ApproveSuggestedAdUnit action = new ApproveSuggestedAdUnit(); // Perform action. SuggestedAdUnitUpdateResult result = suggestedAdUnitService.performSuggestedAdUnitAction( action, statementBuilder.ToStatement()); // Display results. if (result != null && result.numChanges > 0) { Console.WriteLine("Number of new ad units created: " + result.newAdUnitIds.Length); } else { Console.WriteLine("No suggested ad units were approved."); } } catch (Exception e) { Console.WriteLine("Failed to approve suggested ad units. Exception says \"{0}\"", e.Message); } }