/// <summary>
        /// Run the code examples.
        /// </summary>
        public void Run(DfpUser user, long proposalId, long rateCardId, long productId)
        {
            using (ProposalLineItemService proposalLineItemService =
                       (ProposalLineItemService)user.GetService(DfpService.v201805.ProposalLineItemService)) {
                // Create a proposal line item.
                ProposalLineItem proposalLineItem = new ProposalLineItem();
                proposalLineItem.name =
                    "Programmatic proposal line item #" + new Random().Next(int.MaxValue);
                proposalLineItem.proposalId = proposalId;
                proposalLineItem.rateCardId = rateCardId;
                proposalLineItem.productId  = productId;

                // Set the Marketplace information.
                proposalLineItem.marketplaceInfo = new ProposalLineItemMarketplaceInfo()
                {
                    adExchangeEnvironment = AdExchangeEnvironment.DISPLAY
                };

                // Set the length of the proposal line item to run.
                proposalLineItem.startDateTime =
                    DateTimeUtilities.FromDateTime(System.DateTime.Now.AddDays(7), "America/New_York");
                proposalLineItem.endDateTime =
                    DateTimeUtilities.FromDateTime(System.DateTime.Now.AddDays(30), "America/New_York");

                // Set pricing for the proposal line item for 1000 impressions at a CPM of $2
                // for a total value of $2.
                proposalLineItem.goal = new Goal()
                {
                    unitType = UnitType.IMPRESSIONS,
                    units    = 1000L
                };
                proposalLineItem.netCost = new Money()
                {
                    currencyCode = "USD", microAmount = 2000000L
                };
                proposalLineItem.netRate = new Money()
                {
                    currencyCode = "USD", microAmount = 2000000L
                };
                proposalLineItem.rateType = RateType.CPM;

                try {
                    // Create the proposal line item on the server.
                    ProposalLineItem[] proposalLineItems = proposalLineItemService.createProposalLineItems(
                        new ProposalLineItem[] { proposalLineItem });

                    foreach (ProposalLineItem createdProposalLineItem in proposalLineItems)
                    {
                        Console.WriteLine("A programmatic proposal line item with ID \"{0}\" "
                                          + "and name \"{1}\" was created.",
                                          createdProposalLineItem.id,
                                          createdProposalLineItem.name);
                    }
                } catch (Exception e) {
                    Console.WriteLine("Failed to create proposal line items. Exception says \"{0}\"",
                                      e.Message);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            using (ProposalLineItemService proposalLineItemService =
                       (ProposalLineItemService)user.GetService(
                           DfpService.v201802.ProposalLineItemService))
            {
                // Set the ID of the proposal line item.
                long proposalLineItemId = long.Parse(_T("INSERT_PROPOSAL_LINE_ITEM_ID_HERE"));

                // Create a statement to get the proposal line item.
                StatementBuilder statementBuilder = new StatementBuilder()
                                                    .Where("id = :proposalLineItemId").OrderBy("id ASC").Limit(1)
                                                    .AddValue("proposalLineItemId", proposalLineItemId);

                try
                {
                    // Get proposal line items by statement.
                    ProposalLineItemPage page =
                        proposalLineItemService.getProposalLineItemsByStatement(
                            statementBuilder.ToStatement());

                    ProposalLineItem proposalLineItem = page.results[0];

                    // Update proposal line item notes.
                    proposalLineItem.internalNotes = "Proposal line item ready for submission";

                    // Update the proposal line item on the server.
                    ProposalLineItem[] proposalLineItems =
                        proposalLineItemService.updateProposalLineItems(new ProposalLineItem[]
                    {
                        proposalLineItem
                    });

                    if (proposalLineItems != null)
                    {
                        foreach (ProposalLineItem updatedProposalLineItem in proposalLineItems)
                        {
                            Console.WriteLine(
                                "A proposal line item with ID = '{0}' and name '{1}' was updated.",
                                updatedProposalLineItem.id, updatedProposalLineItem.name);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No proposal line items updated.");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(
                        "Failed to update proposal line items. Exception says \"{0}\"", e.Message);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public void Run(DfpUser user, long proposalId)
        {
            ProposalLineItemService proposalLineItemService =
                (ProposalLineItemService)user.GetService(DfpService.v201608.ProposalLineItemService);

            // Create a statement to select proposal line items.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("proposalId = :proposalId")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("proposalId", proposalId);

            // Retrieve a small amount of proposal line items at a time, paging through
            // until all proposal line items have been retrieved.
            ProposalLineItemPage page = new ProposalLineItemPage();

            try {
                do
                {
                    page = proposalLineItemService.getProposalLineItemsByStatement(
                        statementBuilder.ToStatement());

                    if (page.results != null)
                    {
                        // Print out some information for each proposal line item.
                        int i = page.startIndex;
                        foreach (ProposalLineItem proposalLineItem in page.results)
                        {
                            Console.WriteLine("{0}) Proposal line item with ID \"{1}\" "
                                              + "and name \"{2}\" was found.",
                                              i++,
                                              proposalLineItem.id,
                                              proposalLineItem.name);
                        }
                    }

                    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 proposal line items. Exception says \"{0}\"",
                                  e.Message);
            }
        }
Пример #4
0
        /// <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 ProposalLineItemService.
            ProposalLineItemService proposalLineItemService =
                (ProposalLineItemService)user.GetService(DfpService.v201602.ProposalLineItemService);

            // Set the ID of the proposal to get proposal line items from.
            long proposalId = long.Parse(_T("INSERT_PROPOSAL_ID_HERE"));

            // Create a statement to only select proposal line items from a given proposal.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("proposalId = :proposalId")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("proposalId", proposalId);

            // Set default for page.
            ProposalLineItemPage page = new ProposalLineItemPage();

            try {
                do
                {
                    // Get proposal line items by statement.
                    page = proposalLineItemService
                           .getProposalLineItemsByStatement(statementBuilder.ToStatement());

                    if (page.results != null && page.results.Length > 0)
                    {
                        int i = page.startIndex;
                        foreach (ProposalLineItem proposalLineItem in page.results)
                        {
                            Console.WriteLine("{0}) Proposal line item with ID ='{1}' and name '{2}' was found.",
                                              i++, proposalLineItem.id, proposalLineItem.name);
                        }
                    }
                    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 proposal line item by Statement. Exception says \"{0}\"",
                                  e.Message);
            }
        }
Пример #5
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public void Run(DfpUser dfpUser, long proposalId)
        {
            ProposalLineItemService proposalLineItemService =
                (ProposalLineItemService)dfpUser.GetService(DfpService.v201608.ProposalLineItemService);

            // Create a statement to select proposal line items.
            int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT;
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("proposalId = :proposalId")
                                                .OrderBy("id ASC")
                                                .Limit(pageSize)
                                                .AddValue("proposalId", proposalId);

            // Retrieve a small amount of proposal line items at a time, paging through until all
            // proposal line items have been retrieved.
            int totalResultSetSize = 0;

            do
            {
                ProposalLineItemPage page = proposalLineItemService.getProposalLineItemsByStatement(
                    statementBuilder.ToStatement());

                // Print out some information for each proposal line item.
                if (page.results != null)
                {
                    totalResultSetSize = page.totalResultSetSize;
                    int i = page.startIndex;
                    foreach (ProposalLineItem proposalLineItem in page.results)
                    {
                        Console.WriteLine(
                            "{0}) Proposal line item with ID {1} and name \"{2}\" was found.",
                            i++,
                            proposalLineItem.id,
                            proposalLineItem.name
                            );
                    }
                }

                statementBuilder.IncreaseOffsetBy(pageSize);
            } while (statementBuilder.GetOffset() < totalResultSetSize);

            Console.WriteLine("Number of results found: {0}", totalResultSetSize);
        }
Пример #6
0
        /// <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 ProposalLineItemService.
            ProposalLineItemService proposalLineItemService =
                (ProposalLineItemService)user.GetService(DfpService.v201411.ProposalLineItemService);

            // Create a statement to get all proposal line items.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

            // Sets default for page.
            ProposalLineItemPage page = new ProposalLineItemPage();

            try {
                do
                {
                    // Get proposal line items by statement.
                    page = proposalLineItemService
                           .getProposalLineItemsByStatement(statementBuilder.ToStatement());

                    if (page.results != null && page.results.Length > 0)
                    {
                        int i = page.startIndex;
                        foreach (ProposalLineItem proposalLineItem in page.results)
                        {
                            Console.WriteLine("{0}) Proposal line item with ID = '{1}' and name '{2}' was" +
                                              " found.", i++, proposalLineItem.id, proposalLineItem.name);
                        }
                    }

                    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 proposal line items. Exception says \"{0}\"",
                                  e.Message);
            }
        }
        /// <summary>
        /// Run the code examples.
        /// </summary>
        public void Run(AdManagerUser user)
        {
            using (ProposalLineItemService proposalLineItemService =
                       user.GetService <ProposalLineItemService>())

                using (NetworkService networkService = user.GetService <NetworkService>())
                {
                    long proposalId = long.Parse(_T("INSERT_PROPOSAL_ID_HERE"));
                    long rateCardId = long.Parse(_T("INSERT_RATE_CARD_ID_HERE"));
                    long productId  = long.Parse(_T("INSERT_PRODUCT_ID_HERE"));

                    // Get the root ad unit ID used to target the whole site.
                    String rootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId;

                    // Create inventory targeting.
                    InventoryTargeting inventoryTargeting = new InventoryTargeting();

                    // Create ad unit targeting for the root ad unit (i.e. the whole network).
                    AdUnitTargeting adUnitTargeting = new AdUnitTargeting();
                    adUnitTargeting.adUnitId           = rootAdUnitId;
                    adUnitTargeting.includeDescendants = true;

                    inventoryTargeting.targetedAdUnits = new AdUnitTargeting[]
                    {
                        adUnitTargeting
                    };

                    // Create targeting.
                    Targeting targeting = new Targeting();
                    targeting.inventoryTargeting = inventoryTargeting;

                    // Create a proposal line item.
                    ProposalLineItem proposalLineItem = new ProposalLineItem();
                    proposalLineItem.name =
                        "Proposal line item #" + new Random().Next(int.MaxValue);

                    proposalLineItem.proposalId = proposalId;
                    proposalLineItem.rateCardId = rateCardId;
                    proposalLineItem.productId  = productId;
                    proposalLineItem.targeting  = targeting;

                    // Set the length of the proposal line item to run.
                    proposalLineItem.startDateTime =
                        DateTimeUtilities.FromDateTime(System.DateTime.Now.AddDays(7),
                                                       "America/New_York");
                    proposalLineItem.endDateTime =
                        DateTimeUtilities.FromDateTime(System.DateTime.Now.AddDays(30),
                                                       "America/New_York");

                    // Set delivery specifications for the proposal line item.
                    proposalLineItem.deliveryRateType     = DeliveryRateType.EVENLY;
                    proposalLineItem.creativeRotationType = CreativeRotationType.OPTIMIZED;

                    // Set billing specifications for the proposal line item.
                    proposalLineItem.billingCap    = BillingCap.CAPPED_CUMULATIVE;
                    proposalLineItem.billingSource = BillingSource.THIRD_PARTY_VOLUME;

                    // Set pricing for the proposal line item for 1000 impressions at a CPM of $2
                    // for a total value of $2.
                    proposalLineItem.goal = new Goal()
                    {
                        unitType = UnitType.IMPRESSIONS,
                        units    = 1000L
                    };
                    proposalLineItem.netCost = new Money()
                    {
                        currencyCode = "USD",
                        microAmount  = 2000000L
                    };
                    proposalLineItem.netRate = new Money()
                    {
                        currencyCode = "USD",
                        microAmount  = 2000000L
                    };
                    proposalLineItem.rateType = RateType.CPM;

                    try
                    {
                        // Create the proposal line item on the server.
                        ProposalLineItem[] proposalLineItems =
                            proposalLineItemService.createProposalLineItems(new ProposalLineItem[]
                        {
                            proposalLineItem
                        });

                        foreach (ProposalLineItem createdProposalLineItem in proposalLineItems)
                        {
                            Console.WriteLine(
                                "A proposal line item with ID \"{0}\" and name \"{1}\" was " +
                                "created.",
                                createdProposalLineItem.id, createdProposalLineItem.name);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(
                            "Failed to create proposal line items. Exception says \"{0}\"",
                            e.Message);
                    }
                }
        }
        /// <summary>
        /// Run the code examples.
        /// </summary>
        public void Run(AdManagerUser user, long proposalId)
        {
            using (ProposalLineItemService proposalLineItemService =
                       user.GetService <ProposalLineItemService>())

                using (NetworkService networkService = user.GetService <NetworkService>())
                {
                    ProposalLineItem proposalLineItem = new ProposalLineItem();
                    proposalLineItem.name = "Programmatic proposal line item #" +
                                            new Random().Next(int.MaxValue);
                    proposalLineItem.proposalId   = proposalId;
                    proposalLineItem.lineItemType = LineItemType.STANDARD;

                    // Set required Marketplace information.
                    proposalLineItem.marketplaceInfo = new ProposalLineItemMarketplaceInfo()
                    {
                        adExchangeEnvironment = AdExchangeEnvironment.DISPLAY
                    };

                    // Get the root ad unit ID used to target the whole site.
                    String rootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId;

                    // Create inventory targeting.
                    InventoryTargeting inventoryTargeting = new InventoryTargeting();

                    // Create ad unit targeting for the root ad unit (i.e. the whole network).
                    AdUnitTargeting adUnitTargeting = new AdUnitTargeting();
                    adUnitTargeting.adUnitId           = rootAdUnitId;
                    adUnitTargeting.includeDescendants = true;

                    inventoryTargeting.targetedAdUnits = new AdUnitTargeting[]
                    {
                        adUnitTargeting
                    };

                    // Create targeting.
                    Targeting targeting = new Targeting();
                    targeting.inventoryTargeting = inventoryTargeting;
                    proposalLineItem.targeting   = targeting;

                    // Create creative placeholder.
                    Size size = new Size()
                    {
                        width         = 300,
                        height        = 250,
                        isAspectRatio = false
                    };
                    CreativePlaceholder creativePlaceholder = new CreativePlaceholder();
                    creativePlaceholder.size = size;

                    proposalLineItem.creativePlaceholders = new CreativePlaceholder[]
                    {
                        creativePlaceholder
                    };

                    // Set the length of the proposal line item to run.
                    proposalLineItem.startDateTime =
                        DateTimeUtilities.FromDateTime(System.DateTime.Now.AddDays(7),
                                                       "America/New_York");
                    proposalLineItem.endDateTime =
                        DateTimeUtilities.FromDateTime(System.DateTime.Now.AddDays(30),
                                                       "America/New_York");

                    // Set delivery specifications for the proposal line item.
                    proposalLineItem.deliveryRateType = DeliveryRateType.EVENLY;

                    // Set pricing for the proposal line item for 1000 impressions at a CPM of $2
                    // for a total value of $2.
                    proposalLineItem.goal = new Goal()
                    {
                        unitType = UnitType.IMPRESSIONS,
                        units    = 1000L
                    };
                    proposalLineItem.netCost = new Money()
                    {
                        currencyCode = "USD",
                        microAmount  = 2000000L
                    };
                    proposalLineItem.netRate = new Money()
                    {
                        currencyCode = "USD",
                        microAmount  = 2000000L
                    };
                    proposalLineItem.rateType = RateType.CPM;

                    try
                    {
                        // Create the proposal line item on the server.
                        ProposalLineItem[] proposalLineItems =
                            proposalLineItemService.createProposalLineItems(new ProposalLineItem[]
                        {
                            proposalLineItem
                        });

                        foreach (ProposalLineItem createdProposalLineItem in proposalLineItems)
                        {
                            Console.WriteLine(
                                "A programmatic proposal line item with ID \"{0}\" " +
                                "and name \"{1}\" was created.", createdProposalLineItem.id,
                                createdProposalLineItem.name);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(
                            "Failed to create programmatic proposal line items. " +
                            "Exception says \"{0}\"", e.Message);
                    }
                }
        }
Пример #9
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            using (ProposalLineItemService proposalLineItemService =
                       (ProposalLineItemService)user.GetService(DfpService.v201802.ProposalLineItemService)) {
                // Set the ID of the proposal line item to archive.
                long proposalLineItemId = long.Parse(_T("INSERT_PROPOSAL_LINE_ITEM_ID_HERE"));

                // Create statement to select a proposal line item by ID.
                StatementBuilder statementBuilder = new StatementBuilder()
                                                    .Where("id = :id")
                                                    .OrderBy("id ASC")
                                                    .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                    .AddValue("id", proposalLineItemId);

                // Set default for page.
                ProposalLineItemPage page = new ProposalLineItemPage();
                List <string>        proposalLineItemIds = new List <string>();

                try {
                    do
                    {
                        // Get proposal line items by statement.
                        page = proposalLineItemService.getProposalLineItemsByStatement(
                            statementBuilder.ToStatement());

                        if (page.results != null)
                        {
                            int i = page.startIndex;
                            foreach (ProposalLineItem proposalLineItem in page.results)
                            {
                                Console.WriteLine("{0}) Proposal line item with ID ='{1}' will be archived.",
                                                  i++, proposalLineItem.id);
                                proposalLineItemIds.Add(proposalLineItem.id.ToString());
                            }
                        }

                        statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
                    } while (statementBuilder.GetOffset() < page.totalResultSetSize);

                    Console.WriteLine("Number of proposal line items to be archived: {0}",
                                      proposalLineItemIds.Count);

                    if (proposalLineItemIds.Count > 0)
                    {
                        // Modify statement.
                        statementBuilder.RemoveLimitAndOffset();

                        // Create action.
                        Google.Api.Ads.Dfp.v201802.ArchiveProposalLineItems action =
                            new Google.Api.Ads.Dfp.v201802.ArchiveProposalLineItems();

                        // Perform action.
                        UpdateResult result = proposalLineItemService.performProposalLineItemAction(action,
                                                                                                    statementBuilder.ToStatement());

                        // Display results.
                        if (result != null && result.numChanges > 0)
                        {
                            Console.WriteLine("Number of proposal line items archived: {0}", result.numChanges);
                        }
                        else
                        {
                            Console.WriteLine("No proposal line items were archived.");
                        }
                    }
                } catch (Exception e) {
                    Console.WriteLine("Failed to archive proposal line items. Exception says \"{0}\"",
                                      e.Message);
                }
            }
        }