/// <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.v201505.SuggestedAdUnitService); // Set default for page. SuggestedAdUnitPage page = new SuggestedAdUnitPage(); // Create a statement to get all suggested ad units. StatementBuilder statementBuilder = new StatementBuilder() .OrderBy("id ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT); try { do { // Get suggested ad units by statement. page = suggestedAdUnitService.getSuggestedAdUnitsByStatement( statementBuilder.ToStatement()); if (page.results != null) { int i = page.startIndex; foreach (SuggestedAdUnit suggestedAdUnit in page.results) { Console.WriteLine("{0}) Suggested ad unit with ID \"{1}\", and number of requests " + "\"{2}\" was found.", i++, suggestedAdUnit.id, suggestedAdUnit.numRequests); } } 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 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.v201505.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); } }