/// <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.v201405.SuggestedAdUnitService); // Set defaults for page and filterStatement. SuggestedAdUnitPage page = new SuggestedAdUnitPage(); Statement filterStatement = new Statement(); int offset = 0; try { do { // Create a statement to get all suggested ad units. filterStatement.query = "LIMIT 500 OFFSET " + offset; // Get suggested ad units by statement. page = suggestedAdUnitService.getSuggestedAdUnitsByStatement(filterStatement); 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); i++; } } offset += 500; } while (offset < 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.v201405.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 suggested ad units approved: " + result.numChanges); } 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.v201405.SuggestedAdUnitService); // Set the number of requests to 50 or more. long NUMBER_OF_REQUESTS = 50L; // Create a statement to only select suggested ad units that have more // than 50 requests. 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()); 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); 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 suggested ad units. Exception says \"{0}\"", ex.Message); } }