/// <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 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 e) { Console.WriteLine("Failed to get 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.v201311.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. Statement filterStatement = new StatementBuilder("WHERE numRequests > :numRequests LIMIT 500") .AddValue("numRequests", NUMBER_OF_REQUESTS).ToStatement(); try { // Get suggested ad units by statement. SuggestedAdUnitPage 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++; } } 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.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.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.v201411.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); } }
/// <summary> /// Run the code example. /// </summary> public void Run(DfpUser user, long numRequests) { SuggestedAdUnitService suggestedAdUnitService = (SuggestedAdUnitService)user.GetService(DfpService.v201605.SuggestedAdUnitService); // Create a statement to select suggested ad units. StatementBuilder statementBuilder = new StatementBuilder() .Where("numRequests >= :numRequests") .OrderBy("id ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("numRequests", numRequests); // Retrieve a small amount of suggested ad units at a time, paging through // until all suggested ad units have been retrieved. SuggestedAdUnitPage page = new SuggestedAdUnitPage(); try { do { page = suggestedAdUnitService.getSuggestedAdUnitsByStatement( statementBuilder.ToStatement()); if (page.results != null) { // Print out some information for each suggested ad unit. int i = page.startIndex; foreach (SuggestedAdUnit suggestedAdUnit in page.results) { Console.WriteLine("{0}) Suggested ad unit with ID \"{1}\" " + "and num 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: {0}", page.totalResultSetSize); } catch (Exception e) { Console.WriteLine("Failed to get 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 void Run(DfpUser dfpUser, long numRequests) { SuggestedAdUnitService suggestedAdUnitService = (SuggestedAdUnitService)dfpUser.GetService(DfpService.v201611.SuggestedAdUnitService); // Create a statement to select suggested ad units. int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT; StatementBuilder statementBuilder = new StatementBuilder() .Where("numRequests >= :numRequests") .OrderBy("id ASC") .Limit(pageSize) .AddValue("numRequests", numRequests); // Retrieve a small amount of suggested ad units at a time, paging through until all // suggested ad units have been retrieved. int totalResultSetSize = 0; do { SuggestedAdUnitPage page = suggestedAdUnitService.getSuggestedAdUnitsByStatement( statementBuilder.ToStatement()); // Print out some information for each suggested ad unit. if (page.results != null) { totalResultSetSize = page.totalResultSetSize; int i = page.startIndex; foreach (SuggestedAdUnit suggestedAdUnit in page.results) { Console.WriteLine( "{0}) Suggested ad unit with ID \"{1}\" and num requests {2} was found.", i++, suggestedAdUnit.id, suggestedAdUnit.numRequests ); } } statementBuilder.IncreaseOffsetBy(pageSize); } while (statementBuilder.GetOffset() < totalResultSetSize); Console.WriteLine("Number of results found: {0}", totalResultSetSize); }
/// <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.v201602.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 e) { Console.WriteLine("Failed to get 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.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> public void Run(AdManagerUser user) { using (SuggestedAdUnitService suggestedAdUnitService = user.GetService <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. Google.Api.Ads.AdManager.v202011.ApproveSuggestedAdUnits action = new Google.Api.Ads.AdManager.v202011.ApproveSuggestedAdUnits(); // 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); } } }