/// <summary> /// Run the code example. /// </summary> public void Run(AdManagerUser user) { using (LineItemCreativeAssociationService licaService = user.GetService <LineItemCreativeAssociationService>()) { // Set the line item to get LICAs by. long lineItemId = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE")); // Set the creative to get LICAs by. long creativeId = long.Parse(_T("INSERT_CREATIVE_ID_HERE")); // Create a statement to get all LICAs. StatementBuilder statementBuilder = new StatementBuilder() .Where("lineItemId = :lineItemId AND creativeId = :creativeId") .OrderBy("lineItemId ASC, creativeId ASC") .Limit(1) .AddValue("lineItemId", lineItemId) .AddValue("creativeId", creativeId); try { // Get LICAs by statement. LineItemCreativeAssociationPage page = licaService.getLineItemCreativeAssociationsByStatement( statementBuilder.ToStatement()); LineItemCreativeAssociation lica = page.results[0]; // Update the LICA object by changing its destination URL. lica.destinationUrl = "http://news.google.com"; // Update the LICA on the server. LineItemCreativeAssociation[] licas = licaService.updateLineItemCreativeAssociations( new LineItemCreativeAssociation[] { lica }); if (licas != null) { foreach (LineItemCreativeAssociation updatedLica in licas) { Console.WriteLine( "LICA with line item ID = '{0}, creative ID ='{1}' and " + "destination URL '{2}' was updated.", updatedLica.lineItemId, updatedLica.creativeId, updatedLica.destinationUrl); } } else { Console.WriteLine("No LICAs updated."); } } catch (Exception e) { Console.WriteLine("Failed to update LICAs. 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 LineItemCreativeAssociationService. LineItemCreativeAssociationService licaService = (LineItemCreativeAssociationService) user.GetService(DfpService.v201311.LineItemCreativeAssociationService); // Set the line item to get LICAs by. long lineItemId = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE")); // Create a Statement to only select LICAs for the given lineItem ID. Statement statement = new StatementBuilder("WHERE lineItemId = :lineItemId LIMIT 500"). AddValue("lineItemId", lineItemId).ToStatement(); try { // Get LICAs by Statement. LineItemCreativeAssociationPage page = licaService.getLineItemCreativeAssociationsByStatement(statement); if (page.results != null && page.results.Length > 0) { int i = page.startIndex; foreach (LineItemCreativeAssociation lica in page.results) { Console.WriteLine("{0}) LICA with line item ID = '{1}', creative ID ='{2}' and " + "status ='{3}' was found.", i, lica.lineItemId, lica.creativeId, lica.status); i++; } } Console.WriteLine("Number of results found: {0}", page.totalResultSetSize); } catch (Exception ex) { Console.WriteLine("Failed to get LICAs. Exception says \"{0}\"", ex.Message); } }
/// <summary> /// Run the code example. /// </summary> public void Run(DfpUser dfpUser, long lineItemId) { LineItemCreativeAssociationService lineItemCreativeAssociationService = (LineItemCreativeAssociationService)dfpUser.GetService( DfpService.v201611.LineItemCreativeAssociationService); // Create a statement to select line item creative associations. int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT; StatementBuilder statementBuilder = new StatementBuilder() .Where("lineItemId = :lineItemId") .OrderBy("lineItemId ASC, creativeId ASC") .Limit(pageSize) .AddValue("lineItemId", lineItemId); // Retrieve a small amount of line item creative associations at a time, paging through until // all line item creative associations have been retrieved. int totalResultSetSize = 0; do { LineItemCreativeAssociationPage page = lineItemCreativeAssociationService.getLineItemCreativeAssociationsByStatement( statementBuilder.ToStatement()); // Print out some information for each line item creative association. if (page.results != null) { totalResultSetSize = page.totalResultSetSize; int i = page.startIndex; foreach (LineItemCreativeAssociation lica in page.results) { if (lica.creativeSetId != 0) { Console.WriteLine( "{0}) Line item creative association with line item ID {1} " + "and creative set ID {2} was found.", i++, lica.lineItemId, lica.creativeSetId ); } else { Console.WriteLine( "{0}) Line item creative association with line item ID {1} " + "and creative ID {2} was found.", i++, lica.lineItemId, lica.creativeId ); } } } 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 void Run(DfpUser user, long lineItemId) { LineItemCreativeAssociationService lineItemCreativeAssociationService = (LineItemCreativeAssociationService)user.GetService( DfpService.v201605.LineItemCreativeAssociationService); // Create a statement to select line item creative associations. StatementBuilder statementBuilder = new StatementBuilder() .Where("lineItemId = :lineItemId") .OrderBy("lineItemId ASC, creativeId ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("lineItemId", lineItemId); // Retrieve a small amount of line item creative associations at a time, paging through // until all line item creative associations have been retrieved. LineItemCreativeAssociationPage page = new LineItemCreativeAssociationPage(); try { do { page = lineItemCreativeAssociationService.getLineItemCreativeAssociationsByStatement( statementBuilder.ToStatement()); if (page.results != null) { // Print out some information for each line item creative association. int i = page.startIndex; foreach (LineItemCreativeAssociation lineItemCreativeAssociation in page.results) { if (lineItemCreativeAssociation.creativeSetId != null) { Console.WriteLine("{0}) Line item creative association with line item ID \"{1}\" " + "and creative set ID \"{2}\" was found.", i++, lineItemCreativeAssociation.lineItemId, lineItemCreativeAssociation.creativeSetId); } else { Console.WriteLine("{0}) Line item creative association with line item ID \"{1}\" " + "and creative ID \"{2}\" was found.", i++, lineItemCreativeAssociation.lineItemId, lineItemCreativeAssociation.creativeId); } } } 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 line item creative associations. 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 LineItemCreativeAssociationService. LineItemCreativeAssociationService licaService = (LineItemCreativeAssociationService) user.GetService(DfpService.v201311.LineItemCreativeAssociationService); // Create a Statement to get all LICAs. Statement statement = new Statement(); statement.query = "LIMIT 500"; try { // Get LICAs by Statement. LineItemCreativeAssociationPage page = licaService.getLineItemCreativeAssociationsByStatement(statement); if (page.results != null && page.results.Length > 0) { LineItemCreativeAssociation[] licas = page.results; // Update each local LICA object by changing its destination URL. foreach (LineItemCreativeAssociation lica in licas) { lica.destinationUrl = "http://news.google.com"; } // Update the LICAs on the server. licas = licaService.updateLineItemCreativeAssociations(licas); if (licas != null) { foreach (LineItemCreativeAssociation lica in licas) { Console.WriteLine("LICA with line item ID = '{0}, creative ID ='{1}' and " + "destination URL '{2}' was updated.", lica.lineItemId, lica.creativeId, lica.destinationUrl); } } else { Console.WriteLine("No LICAs updated."); } } else { Console.WriteLine("No LICAs found to update."); } } catch (Exception ex) { Console.WriteLine("Failed to update LICAs. 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 LineItemCreativeAssociationService. LineItemCreativeAssociationService licaService = (LineItemCreativeAssociationService) user.GetService(DfpService.v201511.LineItemCreativeAssociationService); // Set the line item to get LICAs by. long lineItemId = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE")); // Create a statement to only select LICAs for the given lineItem ID. StatementBuilder statementBuilder = new StatementBuilder() .Where("lineItemId = :lineItemId") .OrderBy("lineItemId ASC, creativeId ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("lineItemId", lineItemId); // Set default for page. LineItemCreativeAssociationPage page = new LineItemCreativeAssociationPage(); try { do { // Get LICAs by statement. page = licaService.getLineItemCreativeAssociationsByStatement( statementBuilder.ToStatement()); if (page.results != null && page.results.Length > 0) { int i = page.startIndex; foreach (LineItemCreativeAssociation lica in page.results) { Console.WriteLine("{0}) LICA with line item ID = '{1}', creative ID ='{2}' and " + "status ='{3}' was found.", i, lica.lineItemId, lica.creativeId, lica.status); i++; } } 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 LICAs. Exception says \"{0}\"", e.Message); } }
public void TestGetLineItemCreativeAssociationsByStatement() { Statement statement = new Statement(); statement.query = string.Format("WHERE lineItemId = '{0}' LIMIT 500", lineItemId3); LineItemCreativeAssociationPage page = null; Assert.DoesNotThrow(delegate() { page = licaService.getLineItemCreativeAssociationsByStatement(statement); }); Assert.NotNull(page); Assert.NotNull(page.results); Assert.AreEqual(page.totalResultSetSize, 1); Assert.NotNull(page.results[0]); Assert.AreEqual(page.results[0].creativeId, lica1.creativeId); Assert.AreEqual(page.results[0].lineItemId, lica1.lineItemId); }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The DFP user object running the code example.</param> public void Run(DfpUser user) { // Get the LineItemCreativeAssociationService. LineItemCreativeAssociationService licaService = (LineItemCreativeAssociationService) user.GetService(DfpService.v201605.LineItemCreativeAssociationService); // Create a statement to get all LICAs. StatementBuilder statementBuilder = new StatementBuilder() .OrderBy("lineItemId ASC, creativeId ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT); // Set default for page. LineItemCreativeAssociationPage page = new LineItemCreativeAssociationPage(); try { do { // Get LICAs by statement. page = licaService.getLineItemCreativeAssociationsByStatement( statementBuilder.ToStatement()); if (page.results != null) { int i = page.startIndex; foreach (LineItemCreativeAssociation lica in page.results) { Console.WriteLine("{0}) LICA with line item ID = '{1}', creative ID ='{2}' and " + "status ='{3}' was found.", i, lica.lineItemId, lica.creativeId, lica.status); i++; } } 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 all LICAs. 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 LineItemCreativeAssociationService. LineItemCreativeAssociationService licaService = (LineItemCreativeAssociationService) user.GetService(DfpService.v201508.LineItemCreativeAssociationService); // Set the line item to get LICAs by. long lineItemId = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE")); // Create a statement to only select LICAs for the given lineItem ID. StatementBuilder statementBuilder = new StatementBuilder() .Where("lineItemId = :lineItemId") .OrderBy("lineItemId ASC, creativeId ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("lineItemId", lineItemId); // Set default for page. LineItemCreativeAssociationPage page = new LineItemCreativeAssociationPage(); try { do { // Get LICAs by statement. page = licaService.getLineItemCreativeAssociationsByStatement( statementBuilder.ToStatement()); if (page.results != null && page.results.Length > 0) { int i = page.startIndex; foreach (LineItemCreativeAssociation lica in page.results) { Console.WriteLine("{0}) LICA with line item ID = '{1}', creative ID ='{2}' and " + "status ='{3}' was found.", i, lica.lineItemId, lica.creativeId, lica.status); i++; } } 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 LICAs. 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 LineItemCreativeAssociationService. LineItemCreativeAssociationService licaService = (LineItemCreativeAssociationService) user.GetService(DfpService.v201311.LineItemCreativeAssociationService); // Sets defaults for page and Statement. LineItemCreativeAssociationPage page = new LineItemCreativeAssociationPage(); Statement statement = new Statement(); int offset = 0; try { do { // Create a Statement to get all LICAs. statement.query = string.Format("LIMIT 500 OFFSET {0}", offset); // Get LICAs by Statement. page = licaService.getLineItemCreativeAssociationsByStatement(statement); if (page.results != null && page.results.Length > 0) { int i = page.startIndex; foreach (LineItemCreativeAssociation lica in page.results) { Console.WriteLine("{0}) LICA with line item ID = '{1}', creative ID ='{2}' and " + "status ='{3}' was found.", i, lica.lineItemId, lica.creativeId, lica.status); i++; } } offset += 500; } while (page.results != null && page.results.Length == 500); Console.WriteLine("Number of results found: {0}", page.totalResultSetSize); } catch (Exception ex) { Console.WriteLine("Failed to get all LICAs. Exception says \"{0}\"", ex.Message); } }
/// <summary> /// Run the code example. /// </summary> public void Run(AdManagerUser user) { using (LineItemCreativeAssociationService licaService = user.GetService <LineItemCreativeAssociationService>()) { // Set the line item to get LICAs by. long lineItemId = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE")); // Create a statement to page through active LICAs. StatementBuilder statementBuilder = new StatementBuilder() .Where("lineItemId = :lineItemId").OrderBy("lineItemId ASC, creativeId ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("lineItemId", lineItemId); // Set default for page. LineItemCreativeAssociationPage page = new LineItemCreativeAssociationPage(); List <string> creativeIds = new List <string>(); try { do { // Get LICAs by statement. page = licaService.getLineItemCreativeAssociationsByStatement( statementBuilder.ToStatement()); if (page.results != null) { int i = page.startIndex; foreach (LineItemCreativeAssociation lica in page.results) { Console.WriteLine( "{0}) LICA with line item ID = '{1}', creative ID ='{2}' and " + "status ='{3}' will be deactivated.", i, lica.lineItemId, lica.creativeId, lica.status); i++; creativeIds.Add(lica.creativeId.ToString()); } } statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT); } while (statementBuilder.GetOffset() < page.totalResultSetSize); Console.WriteLine("Number of LICAs to be deactivated: {0}", creativeIds.Count); if (creativeIds.Count > 0) { // Modify statement for action. statementBuilder.RemoveLimitAndOffset(); // Create action. DeactivateLineItemCreativeAssociations action = new DeactivateLineItemCreativeAssociations(); // Perform action. UpdateResult result = licaService.performLineItemCreativeAssociationAction(action, statementBuilder.ToStatement()); // Display results. if (result != null && result.numChanges > 0) { Console.WriteLine("Number of LICAs deactivated: {0}", result.numChanges); } else { Console.WriteLine("No LICAs were deactivated."); } } } catch (Exception e) { Console.WriteLine("Failed to deactivate LICAs. 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 LineItemCreativeAssociationService. LineItemCreativeAssociationService licaService = (LineItemCreativeAssociationService) user.GetService(DfpService.v201511.LineItemCreativeAssociationService); // Set the line item to get LICAs by. long lineItemId = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE")); // Create a statement to page through LICAs. StatementBuilder statementBuilder = new StatementBuilder() .Where("lineItemId = :lineItemId") .OrderBy("lineItemId ASC, creativeId ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("lineItemId", lineItemId); // Set default for page. LineItemCreativeAssociationPage page = new LineItemCreativeAssociationPage(); List<string> creativeIds = new List<string>(); try { do { // Get LICAs by statement. page = licaService.getLineItemCreativeAssociationsByStatement( statementBuilder.ToStatement()); if (page.results != null && page.results.Length > 0) { int i = page.startIndex; foreach (LineItemCreativeAssociation lica in page.results) { Console.WriteLine("{0}) LICA with line item ID = '{1}', creative ID ='{2}' and " + "status ='{3}' will be activated.", i, lica.lineItemId, lica.creativeId, lica.status); i++; creativeIds.Add(lica.creativeId.ToString()); } } statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT); } while (statementBuilder.GetOffset() < page.totalResultSetSize); Console.WriteLine("Number of LICAs to be activated: {0}", creativeIds.Count); if (creativeIds.Count > 0) { // Modify statement for action. statementBuilder.RemoveLimitAndOffset(); // Create action. ActivateLineItemCreativeAssociations action = new ActivateLineItemCreativeAssociations(); // Perform action. UpdateResult result = licaService.performLineItemCreativeAssociationAction(action, statementBuilder.ToStatement()); // Display results. if (result != null && result.numChanges > 0) { Console.WriteLine("Number of LICAs activated: {0}", result.numChanges); } else { Console.WriteLine("No LICAs were activated."); } } } catch (Exception e) { Console.WriteLine("Failed to activate LICAs. 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 LineItemCreativeAssociationService. LineItemCreativeAssociationService licaService = (LineItemCreativeAssociationService) user.GetService(DfpService.v201311.LineItemCreativeAssociationService); // Set the line item to get LICAs by. long lineItemId = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE")); String statementText = "WHERE lineItemId = :lineItemId and status = :status LIMIT 500"; Statement statement = new StatementBuilder("").AddValue("lineItemId", lineItemId). AddValue("status", LineItemCreativeAssociationStatus.ACTIVE.ToString()).ToStatement(); // Sets defaults for page and offset. LineItemCreativeAssociationPage page = new LineItemCreativeAssociationPage(); int offset = 0; List <string> creativeIds = new List <string>(); try { do { // Create a Statement to page through active LICAs. statement.query = string.Format("{0} OFFSET {1}", statementText, offset); // Get LICAs by Statement. page = licaService.getLineItemCreativeAssociationsByStatement(statement); if (page.results != null && page.results.Length > 0) { int i = page.startIndex; foreach (LineItemCreativeAssociation lica in page.results) { Console.WriteLine("{0}) LICA with line item ID = '{1}', creative ID ='{2}' and " + "status ='{3}' will be deactivated.", i, lica.lineItemId, lica.creativeId, lica.status); i++; creativeIds.Add(lica.creativeId.ToString()); } } offset += 500; } while (offset < page.totalResultSetSize); Console.WriteLine("Number of LICAs to be deactivated: {0}", creativeIds.Count); if (creativeIds.Count > 0) { // Create action Statement. statement = new StatementBuilder( string.Format("WHERE lineItemId = :lineItemId and creativeId IN ({0})", string.Join(",", creativeIds.ToArray()))). AddValue("lineItemId", lineItemId).ToStatement(); // Create action. DeactivateLineItemCreativeAssociations action = new DeactivateLineItemCreativeAssociations(); // Perform action. UpdateResult result = licaService.performLineItemCreativeAssociationAction(action, statement); // Display results. if (result != null && result.numChanges > 0) { Console.WriteLine("Number of LICAs deactivated: {0}", result.numChanges); } else { Console.WriteLine("No LICAs were deactivated."); } } } catch (Exception ex) { Console.WriteLine("Failed to deactivate LICAs. Exception says \"{0}\"", ex.Message); } }