/// <summary> /// Run the code example. /// </summary> public void Run(AdManagerUser user) { using (AudienceSegmentService audienceSegmentService = user.GetService <AudienceSegmentService>()) { long audienceSegmentId = long.Parse(_T("INSERT_AUDIENCE_SEGMENT_ID_HERE")); // Create a statement to only select a specified first party audience // segment. StatementBuilder statementBuilder = new StatementBuilder() .Where("id = :audienceSegmentId").OrderBy("id ASC").Limit(1) .AddValue("audienceSegmentId", audienceSegmentId); try { // Get audience segment by statement. AudienceSegment audienceSegment = audienceSegmentService .getAudienceSegmentsByStatement(statementBuilder.ToStatement()).results[0]; Console.WriteLine( "Audience segment with id \"{0}\" and name \"{1}\" " + "will be populated", audienceSegment.id, audienceSegment.name); // Create action. PopulateAudienceSegments action = new PopulateAudienceSegments(); // Perform action. UpdateResult result = audienceSegmentService.performAudienceSegmentAction(action, statementBuilder.ToStatement()); if (result != null && result.numChanges > 0) { Console.WriteLine("Number of audience segments populated: {0}", result.numChanges); } else { Console.WriteLine("No audience segments were populated."); } } catch (Exception e) { Console.WriteLine("Failed to populate audience segment. 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 AudienceSegmentService. AudienceSegmentService audienceSegmentService = (AudienceSegmentService)user.GetService(DfpService.v201311.AudienceSegmentService); long audienceSegmentId = long.Parse(_T("INSERT_AUDIENCE_SEGMENT_ID_HERE")); // Create a statement to only select a specified first party audience // segment. string statementText = "where id = :audienceSegmentId order by id ASC " + "LIMIT 1"; Statement statement = new StatementBuilder(statementText) .AddValue("audienceSegmentId", audienceSegmentId) .ToStatement(); try { // Get audience segment by Statement. AudienceSegment audienceSegment = audienceSegmentService.getAudienceSegmentsByStatement(statement).results[0]; Console.WriteLine("Audience segment with id \"{0}\" and name \"{1}\" " + "will be populated", audienceSegment.id, audienceSegment.name); // Create action. PopulateAudienceSegments action = new PopulateAudienceSegments(); statement.query = statementText; // Perform action. UpdateResult result = audienceSegmentService.performAudienceSegmentAction( action, statement); if (result != null && result.numChanges > 0) { Console.WriteLine("Number of audience segments populated: {0}", result.numChanges); } else { Console.WriteLine("No audience segments were populated."); } } catch (Exception ex) { Console.WriteLine("Failed to populate audience segment. Exception says \"{0}\"", ex.Message); } }