コード例 #1
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(AdManagerUser user)
        {
            try
            {
                // Get all ad units.
                AdUnit[] allAdUnits = GetAllAdUnits(user);

                // Find the root ad unit. rootAdUnit can also be set to child unit to
                // only build and display a portion of the tree.
                // i.e. AdUnit adUnit =
                //          inventoryService.getAdUnit("INSERT_AD_UNIT_HERE")
                AdUnit rootAdUnit = FindRootAdUnit(user);

                if (rootAdUnit == null)
                {
                    Console.WriteLine("Could not build tree. No root ad unit found.");
                }
                else
                {
                    BuildAndDisplayAdUnitTree(rootAdUnit, allAdUnits);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to get ad unit. Exception says \"{0}\"", e.Message);
            }
        }
        internal void RunCalls()
        {
            Console.WriteLine("For the rest of the samples you'll need a Publisher ID. If you haven't associated an " +
                              "AdSense account to your Host, set AssociationSession.cs as startup object and rebuild.");

            // Get publisher ID from user.
            Console.WriteLine("Insert Publisher ID");
            string publisherId = Console.ReadLine();

            if (string.IsNullOrEmpty(publisherId))
            {
                return;
            }

            AdClients publisherAdClients = GetAllAdClients(publisherId);

            if (publisherAdClients.Items != null && publisherAdClients.Items.Count > 0)
            {
                // Get a host ad client ID, so we can run the rest of the samples.
                string examplePublisherAdClientId = publisherAdClients.Items[0].Id;

                GetAllAdUnits(publisherId, examplePublisherAdClientId);
                AdUnit adUnit = AddAdUnit(publisherId,
                                          examplePublisherAdClientId);
                adUnit = UpdateAdUnit(publisherId, examplePublisherAdClientId, adUnit.Id);
                DeleteAdUnit(publisherId, examplePublisherAdClientId, adUnit.Id);
                GenerateReport(publisherId, examplePublisherAdClientId);
            }
        }
コード例 #3
0
        public void TestUpdateAdUnit()
        {
            List <AdUnitSize> adUnitSizes = new List <AdUnitSize>(adUnit1.adUnitSizes);

            Size size = new Size();

            size.width  = 728;
            size.height = 90;

            // Create ad unit size.
            AdUnitSize adUnitSize = new AdUnitSize();

            adUnitSize.size            = size;
            adUnitSize.environmentType = EnvironmentType.BROWSER;

            adUnitSizes.Add(adUnitSize);
            adUnit1.adUnitSizes = adUnitSizes.ToArray();

            AdUnit newAdUnit = null;

            Assert.DoesNotThrow(delegate() {
                newAdUnit = inventoryService.updateAdUnit(adUnit1);
            });

            Assert.NotNull(newAdUnit);

            Assert.AreEqual(newAdUnit.name, adUnit1.name);
            Assert.AreEqual(newAdUnit.parentId, adUnit1.parentId);
            Assert.AreEqual(newAdUnit.id, adUnit1.id);
            Assert.AreEqual(newAdUnit.status, adUnit1.status);
            Assert.AreEqual(newAdUnit.targetWindow, adUnit1.targetWindow);
            Assert.AreEqual(newAdUnit.adUnitSizes.Length, adUnit1.adUnitSizes.Length);
        }
コード例 #4
0
        public void TestCreateAdUnit()
        {
            AdUnit localAdUnit = new AdUnit();

            localAdUnit.name     = string.Format("Ad_Unit_{0}", new TestUtils().GetTimeStamp());
            localAdUnit.parentId = adUnit1.id;

            Size size = new Size();

            size.width  = 300;
            size.height = 250;

            // Create ad unit size.
            AdUnitSize adUnitSize = new AdUnitSize();

            adUnitSize.size            = size;
            adUnitSize.environmentType = EnvironmentType.BROWSER;

            localAdUnit.adUnitSizes = new AdUnitSize[] { adUnitSize };

            AdUnit newAdUnit = null;

            Assert.DoesNotThrow(delegate() {
                newAdUnit = inventoryService.createAdUnit(localAdUnit);
            });

            Assert.NotNull(newAdUnit);
            Assert.AreEqual(newAdUnit.name, localAdUnit.name);
            Assert.AreEqual(newAdUnit.parentId, localAdUnit.parentId);
            Assert.AreEqual(newAdUnit.parentId, adUnit1.id);
            Assert.AreEqual(newAdUnit.status, localAdUnit.status);
            Assert.AreEqual(newAdUnit.targetWindow, localAdUnit.targetWindow);
        }
コード例 #5
0
        public AdUnit CreateAdUnit(DfpUser user)
        {
            InventoryService inventoryService =
                (InventoryService)user.GetService(DfpService.v201602.InventoryService);

            AdUnit adUnit = new AdUnit();

            adUnit.name     = string.Format("Ad_Unit_{0}", GetTimeStamp());
            adUnit.parentId = FindRootAdUnit(user).id;

            // Set the size of possible creatives that can match this ad unit.
            Size size = new Size();

            size.width  = 300;
            size.height = 250;

            // Create ad unit size.
            AdUnitSize adUnitSize = new AdUnitSize();

            adUnitSize.size            = size;
            adUnitSize.environmentType = EnvironmentType.BROWSER;

            adUnit.adUnitSizes = new AdUnitSize[] { adUnitSize };
            return(inventoryService.createAdUnits(new AdUnit[] { adUnit })[0]);
        }
コード例 #6
0
        /// <summary>
        /// Builds and displays an ad unit tree from an array of ad units underneath
        /// the root ad unit.
        /// </summary>
        /// <param name="root">The root ad unit to build the tree under.</param>
        /// <param name="units">The array of ad units.</param>
        private static void BuildAndDisplayAdUnitTree(AdUnit root, AdUnit[] units)
        {
            Dictionary <String, List <AdUnit> > treeMap = new Dictionary <String, List <AdUnit> >();

            foreach (AdUnit unit in units)
            {
                if (unit.parentId != null)
                {
                    if (treeMap.ContainsKey(unit.parentId) == false)
                    {
                        treeMap.Add(unit.parentId, new List <AdUnit>());
                    }
                    treeMap[unit.parentId].Add(unit);
                }
            }

            if (root != null)
            {
                DisplayInventoryTree(root, treeMap);
            }
            else
            {
                Console.WriteLine("No root unit found.");
            }
        }
コード例 #7
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 InventoryService.
            InventoryService inventoryService =
                (InventoryService)user.GetService(DfpService.v201311.InventoryService);

            // Set the ID of the ad unit to get.
            String adUnitId = _T("INSERT_AD_UNIT_ID_HERE");

            try {
                // Get the ad unit.
                AdUnit adUnit = inventoryService.getAdUnit(adUnitId);

                if (adUnit != null)
                {
                    Console.WriteLine("Ad unit with ID = '{0}', name = '{1}' and status = '{2}' was found.",
                                      adUnit.id, adUnit.name, adUnit.status);
                }
                else
                {
                    Console.WriteLine("No ad unit found for this ID.");
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to get ad unit. Exception says \"{0}\"", ex.Message);
            }
        }
コード例 #8
0
 public void Init() {
   TestUtils utils = new TestUtils();
   placementService = (PlacementService) user.GetService(DfpService.v201511.PlacementService);
   adUnit1 = utils.CreateAdUnit(user);
   adUnit2 = utils.CreateAdUnit(user);
   placement = utils.CreatePlacement(user, new string[] {adUnit1.id, adUnit2.id});
 }
コード例 #9
0
        public void TestCreateAdUnits()
        {
            // Create ad unit 1.
            AdUnit localAdUnit1 = new AdUnit();

            localAdUnit1.name     = string.Format("Ad_Unit_{0}", new TestUtils().GetTimeStamp());
            localAdUnit1.parentId = adUnit1.id;

            Size size1 = new Size();

            size1.width  = 300;
            size1.height = 250;

            AdUnitSize adUnitSize1 = new AdUnitSize();

            adUnitSize1.size            = size1;
            adUnitSize1.environmentType = EnvironmentType.BROWSER;

            localAdUnit1.adUnitSizes = new AdUnitSize[] { adUnitSize1 };

            // Create ad unit 2.
            AdUnit localAdUnit2 = new AdUnit();

            localAdUnit2.name     = string.Format("Ad_Unit_{0}", new TestUtils().GetTimeStamp());
            localAdUnit2.parentId = adUnit1.id;

            Size size2 = new Size();

            size2.width  = 300;
            size2.height = 250;

            AdUnitSize adUnitSize2 = new AdUnitSize();

            adUnitSize2.size            = size2;
            adUnitSize2.environmentType = EnvironmentType.BROWSER;

            localAdUnit2.adUnitSizes = new AdUnitSize[] { adUnitSize2 };

            AdUnit[] newAdUnits = null;

            Assert.DoesNotThrow(delegate() {
                newAdUnits = inventoryService.createAdUnits(new AdUnit[] { localAdUnit1, localAdUnit2 });
            });

            Assert.NotNull(newAdUnits);
            Assert.AreEqual(newAdUnits.Length, 2);

            Assert.AreEqual(newAdUnits[0].name, localAdUnit1.name);
            Assert.AreEqual(newAdUnits[0].parentId, localAdUnit1.parentId);
            Assert.AreEqual(newAdUnits[0].parentId, adUnit1.id);
            Assert.AreEqual(newAdUnits[0].status, localAdUnit1.status);
            Assert.AreEqual(newAdUnits[0].targetWindow, localAdUnit1.targetWindow);

            Assert.AreEqual(newAdUnits[1].name, localAdUnit2.name);
            Assert.AreEqual(newAdUnits[1].parentId, localAdUnit2.parentId);
            Assert.AreEqual(newAdUnits[1].parentId, adUnit1.id);
            Assert.AreEqual(newAdUnits[1].status, localAdUnit2.status);
            Assert.AreEqual(newAdUnits[1].targetWindow, localAdUnit2.targetWindow);
        }
コード例 #10
0
        public void Init()
        {
            TestUtils utils = new TestUtils();

            inventoryService = (InventoryService)user.GetService(DfpService.v201308.InventoryService);
            adUnit1          = utils.CreateAdUnit(user);
            adUnit2          = utils.CreateAdUnit(user);
        }
コード例 #11
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            // Get the InventoryService.
            InventoryService inventoryService =
                (InventoryService)user.GetService(DfpService.v201602.InventoryService);

            // Get the NetworkService.
            NetworkService networkService =
                (NetworkService)user.GetService(DfpService.v201602.NetworkService);

            string effectiveRootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId;

            // Create an array to store local ad unit objects.
            AdUnit[] adUnits = new AdUnit[5];

            for (int i = 0; i < 5; i++)
            {
                AdUnit adUnit = new AdUnit();
                adUnit.name     = string.Format("Ad_Unit_{0}", i);
                adUnit.parentId = effectiveRootAdUnitId;

                adUnit.description  = "Ad unit description.";
                adUnit.targetWindow = AdUnitTargetWindow.BLANK;

                // Set the size of possible creatives that can match this ad unit.
                Size size = new Size();
                size.width  = 300;
                size.height = 250;

                // Create ad unit size.
                AdUnitSize adUnitSize = new AdUnitSize();
                adUnitSize.size            = size;
                adUnitSize.environmentType = EnvironmentType.BROWSER;

                adUnit.adUnitSizes = new AdUnitSize[] { adUnitSize };
                adUnits[i]         = adUnit;
            }

            try {
                // Create the ad units on the server.
                adUnits = inventoryService.createAdUnits(adUnits);

                if (adUnits != null)
                {
                    foreach (AdUnit adUnit in adUnits)
                    {
                        Console.WriteLine("An ad unit with ID = '{0}' was created under parent with " +
                                          "ID = '{1}'.", adUnit.id, adUnit.parentId);
                    }
                }
                else
                {
                    Console.WriteLine("No ad units created.");
                }
            } catch (Exception e) {
                Console.WriteLine("Failed to create ad units. Exception says \"{0}\"", e.Message);
            }
        }
コード例 #12
0
        public void Init()
        {
            TestUtils utils = new TestUtils();

            placementService = (PlacementService)user.GetService(DfpService.v201502.PlacementService);
            adUnit1          = utils.CreateAdUnit(user);
            adUnit2          = utils.CreateAdUnit(user);
            placement        = utils.CreatePlacement(user, new string[] { adUnit1.id, adUnit2.id });
        }
コード例 #13
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 InventoryService.
      InventoryService inventoryService =
          (InventoryService) user.GetService(DfpService.v201508.InventoryService);

      // Get the NetworkService.
      NetworkService networkService =
          (NetworkService) user.GetService(DfpService.v201508.NetworkService);

      string effectiveRootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId;

      // Create an array to store local ad unit objects.
      AdUnit[] adUnits = new AdUnit[5];

      for (int i = 0; i < 5; i++) {
        AdUnit adUnit = new AdUnit();
        adUnit.name = string.Format("Ad_Unit_{0}", i);
        adUnit.parentId = effectiveRootAdUnitId;

        adUnit.description = "Ad unit description.";
        adUnit.targetWindow = AdUnitTargetWindow.BLANK;

        // Set the size of possible creatives that can match this ad unit.
        Size size = new Size();
        size.width = 300;
        size.height = 250;

        // Create ad unit size.
        AdUnitSize adUnitSize = new AdUnitSize();
        adUnitSize.size = size;
        adUnitSize.environmentType = EnvironmentType.BROWSER;

        adUnit.adUnitSizes = new AdUnitSize[] {adUnitSize};
        adUnits[i] = adUnit;
      }

      try {
        // Create the ad units on the server.
        adUnits = inventoryService.createAdUnits(adUnits);

        if (adUnits != null) {
          foreach (AdUnit adUnit in adUnits) {
            Console.WriteLine("An ad unit with ID = '{0}' was created under parent with " +
                "ID = '{1}'.", adUnit.id, adUnit.parentId);
          }
        } else {
          Console.WriteLine("No ad units created.");
        }
      } catch (Exception e) {
        Console.WriteLine("Failed to create ad units. Exception says \"{0}\"", e.Message);
      }
    }
コード例 #14
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 InventoryService.
            InventoryService inventoryService =
                (InventoryService)user.GetService(DfpService.v201311.InventoryService);

            // Get the NetworkService.
            NetworkService networkService =
                (NetworkService)user.GetService(DfpService.v201311.NetworkService);

            // Set the parent ad unit's ID for all ad units to be created under.
            String effectiveRootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId;

            // Create local ad unit object.
            AdUnit adUnit = new AdUnit();

            adUnit.name           = "Mobile_Ad_Unit";
            adUnit.parentId       = effectiveRootAdUnitId;
            adUnit.description    = "Ad unit description.";
            adUnit.targetWindow   = AdUnitTargetWindow.BLANK;
            adUnit.targetPlatform = TargetPlatform.MOBILE;

            // Create ad unit size.
            AdUnitSize adUnitSize = new AdUnitSize();
            Size       size       = new Size();

            size.width                 = 400;
            size.height                = 300;
            size.isAspectRatio         = false;
            adUnitSize.size            = size;
            adUnitSize.environmentType = EnvironmentType.BROWSER;

            // Set the size of possible creatives that can match this ad unit.
            adUnit.adUnitSizes = new AdUnitSize[] { adUnitSize };

            try {
                // Create the ad unit on the server.
                adUnit = inventoryService.createAdUnit(adUnit);

                if (adUnit != null)
                {
                    Console.WriteLine("An ad unit with ID \"{0}\" was created under parent with ID \"{1}\".",
                                      adUnit.id, adUnit.parentId);
                }
                else
                {
                    Console.WriteLine("No ad units created.");
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to create ad units. Exception says \"{0}\"", ex.Message);
            }
        }
コード例 #15
0
    public void TestCreateAdUnits() {
      // Create ad unit 1.
      AdUnit localAdUnit1 = new AdUnit();
      localAdUnit1.name = string.Format("Ad_Unit_{0}", new TestUtils().GetTimeStamp());
      localAdUnit1.parentId = adUnit1.id;

      Size size1 = new Size();
      size1.width = 300;
      size1.height = 250;

      AdUnitSize adUnitSize1 = new AdUnitSize();
      adUnitSize1.size = size1;
      adUnitSize1.environmentType = EnvironmentType.BROWSER;

      localAdUnit1.adUnitSizes = new AdUnitSize[] {adUnitSize1};

      // Create ad unit 2.
      AdUnit localAdUnit2 = new AdUnit();
      localAdUnit2.name = string.Format("Ad_Unit_{0}", new TestUtils().GetTimeStamp());
      localAdUnit2.parentId = adUnit1.id;

      Size size2 = new Size();
      size2.width = 300;
      size2.height = 250;

      AdUnitSize adUnitSize2 = new AdUnitSize();
      adUnitSize2.size = size2;
      adUnitSize2.environmentType = EnvironmentType.BROWSER;

      localAdUnit2.adUnitSizes = new AdUnitSize[] {adUnitSize2};

      AdUnit[] newAdUnits = null;

      Assert.DoesNotThrow(delegate() {
        newAdUnits = inventoryService.createAdUnits(new AdUnit[] {localAdUnit1, localAdUnit2});
      });

      Assert.NotNull(newAdUnits);
      Assert.AreEqual(newAdUnits.Length, 2);

      Assert.AreEqual(newAdUnits[0].name, localAdUnit1.name);
      Assert.AreEqual(newAdUnits[0].parentId, localAdUnit1.parentId);
      Assert.AreEqual(newAdUnits[0].parentId, adUnit1.id);
      Assert.AreEqual(newAdUnits[0].status, localAdUnit1.status);
      Assert.AreEqual(newAdUnits[0].targetWindow, localAdUnit1.targetWindow);

      Assert.AreEqual(newAdUnits[1].name, localAdUnit2.name);
      Assert.AreEqual(newAdUnits[1].parentId, localAdUnit2.parentId);
      Assert.AreEqual(newAdUnits[1].parentId, adUnit1.id);
      Assert.AreEqual(newAdUnits[1].status, localAdUnit2.status);
      Assert.AreEqual(newAdUnits[1].targetWindow, localAdUnit2.targetWindow);
    }
コード例 #16
0
        /// <summary>
        /// Placeholder that is replaced with ads.
        /// </summary>
        /// <param name="unitName">Name of the ad unit as set in DFP.</param>
        /// <param name="size">Specify creative sizes in the googletag.defineSlot() function. To allow multiple sizes to serve to the ad slot, you can use a comma-separated list.</param>
        /// <param name="cssClass">CSS class to add to the ad unit div container.</param>
        /// <param name="tagName">Type of parent container, must be block</param>
        /// <param name="sizeMapping">Specify creative sizes in the googletag.defineSlot() function. To allow multiple sizes to serve to the ad slot, you can use a comma-separated list.</param>
        /// <param name="display">Should display be called when the dfp script is initialised?</param>
        /// <param name="targeting">GA slot specific targeting</param>
        /// <returns>HTML container object.</returns>
        public static IHtmlString Placeholder(string unitName, string size, string cssClass, string tagName, string sizeMapping, bool display, Dictionary <string, string> targeting)
        {
            if (String.IsNullOrWhiteSpace(unitName))
            {
                throw new ArgumentNullException("unitName");
            }

            cssClass    = cssClass ?? "";
            tagName     = tagName ?? "div";
            targeting   = targeting ?? new Dictionary <string, string>();
            sizeMapping = sizeMapping ?? "";

            if (String.IsNullOrWhiteSpace(tagName))
            {
                throw new ArgumentNullException("tagName");
            }

            var containerId = "div-gpt-ad-" + _adCounter;

            string placeholder = String.Format(
                CultureInfo.InvariantCulture,
                "<{0} id=\"{1}\" class=\"{2}\" data-cb-ad-id=\"{3}\"><!-- {3} --></{0}>",
                tagName,
                containerId,
                cssClass,
                unitName);

            var unit = new AdUnit
            {
                UnitName  = unitName,
                Size      = size,
                Display   = display,
                Id        = containerId,
                Targeting = targeting
            };

            if (!string.IsNullOrWhiteSpace(sizeMapping))
            {
                // Confirm the mapping exists
                if (!SizeUnits.ContainsKey(sizeMapping))
                {
                    throw new ArgumentException(String.Format("Size unit '{0}' not defined. Sizes must be defined before adding to a unit.", sizeMapping), "sizeMapping");
                }
                unit.SizeMapping = sizeMapping;
            }

            AdUnits.Add(unit);

            _adCounter++;

            return(new HtmlString(placeholder));
        }
コード例 #17
0
        /// <summary>
        /// Helper for displaying inventory units.
        /// </summary>
        /// <param name="root">The root inventory unit.</param>
        /// <param name="treeMap">The map of id to List of inventory units.</param>
        /// <param name="depth">The depth the tree has reached.</param>
        private static void DisplayInventoryTreeHelper(AdUnit root,
                                                       Dictionary <String, List <AdUnit> > treeMap, int depth)
        {
            Console.WriteLine(GenerateTab(depth) + root.name + " (" + root.id + ")");

            if (treeMap.ContainsKey(root.id))
            {
                foreach (AdUnit child in treeMap[root.id])
                {
                    DisplayInventoryTreeHelper(child, treeMap, depth + 1);
                }
            }
        }
        /// <summary>This example deletes an Ad Unit on a publisher ad client.</summary>
        /// <param name="accountId">The ID for the publisher account to be used.</param>
        /// <param name="adClientId">The ID for the ad client to be used.</param>
        /// <param name="adUnitId">The ID for the Ad Unit to be deleted.</param>
        private void DeleteAdUnit(string accountId, string adClientId, string adUnitId)
        {
            Console.WriteLine("=================================================================");
            Console.WriteLine("Deleting ad unit {0}", adUnitId);
            Console.WriteLine("=================================================================");

            // Delete ad unit
            AdUnit adUnit = this.service.Accounts.Adunits.Delete(accountId, adClientId, adUnitId).Execute();

            Console.WriteLine("Ad unit with id {0} was deleted.", adUnitId);

            Console.WriteLine();
        }
コード例 #19
0
        /// <summary>
        /// Run the sample code.
        /// </summary>
        public void Run(DfpUser user, long adUnitId)
        {
            using (InventoryService inventoryService =
                       (InventoryService)user.GetService(DfpService.v201708.InventoryService)) {
                // Create a statement to get the ad unit.
                StatementBuilder statementBuilder = new StatementBuilder()
                                                    .Where("id = :id")
                                                    .OrderBy("id ASC")
                                                    .Limit(1)
                                                    .AddValue("id", adUnitId);

                try {
                    // Get ad units by statement.
                    AdUnitPage page = inventoryService.getAdUnitsByStatement(statementBuilder.ToStatement());

                    // Create a 480x60 web ad unit size.
                    AdUnitSize adUnitSize = new AdUnitSize()
                    {
                        size = new Size()
                        {
                            width  = 480,
                            height = 60
                        },
                        environmentType = EnvironmentType.BROWSER
                    };

                    AdUnit adUnit = page.results[0];
                    adUnit.adUnitSizes = new AdUnitSize[] { adUnitSize };

                    // Update the ad units on the server.
                    AdUnit[] updatedAdUnits = inventoryService.updateAdUnits(new AdUnit[] { adUnit });

                    foreach (AdUnit updatedAdUnit in updatedAdUnits)
                    {
                        List <string> adUnitSizeStrings = new List <string>();
                        foreach (AdUnitSize size in updatedAdUnit.adUnitSizes)
                        {
                            adUnitSizeStrings.Add(size.fullDisplayString);
                        }
                        Console.WriteLine("Ad unit with ID \"{0}\", name \"{1}\", and sizes [{2}] was " +
                                          "updated.", updatedAdUnit.id, updatedAdUnit.name,
                                          String.Join(",", adUnitSizeStrings));
                    }
                } catch (Exception e) {
                    Console.WriteLine("Failed to update ad units. Exception says \"{0}\"", e.Message);
                }
            }
        }
        /// <summary>This example adds a new ad unit to a publisher ad client.</summary>
        /// <param name="accountId">The ID for the publisher account to be used.</param>
        /// <param name="adClientId">An arbitrary publisher ad client ID.</param>
        /// <returns>The created ad unit.</returns>
        private AdUnit AddAdUnit(string accountId, string adClientId)
        {
            Console.WriteLine("=================================================================");
            Console.WriteLine("Adding ad unit to ad client {0}", accountId);
            Console.WriteLine("=================================================================");

            AdUnit newAdUnit = new AdUnit();

            Random random = new Random(DateTime.Now.Millisecond);

            newAdUnit.Name = "Ad Unit #"
                             + random.Next(0, 10000).ToString();

            newAdUnit.ContentAdsSettings = new AdUnit.ContentAdsSettingsData();
            newAdUnit.ContentAdsSettings.BackupOption = new AdUnit.ContentAdsSettingsData.BackupOptionData();

            newAdUnit.ContentAdsSettings.BackupOption.Type  = "COLOR";
            newAdUnit.ContentAdsSettings.BackupOption.Color = "ffffff";
            newAdUnit.ContentAdsSettings.Size       = "SIZE_200_200";
            newAdUnit.ContentAdsSettings.Type       = "TEXT";
            newAdUnit.CustomStyle                   = new AdStyle();
            newAdUnit.CustomStyle.Colors            = new AdStyle.ColorsData();
            newAdUnit.CustomStyle.Colors.Background = "ffffff";
            newAdUnit.CustomStyle.Colors.Border     = "000000";
            newAdUnit.CustomStyle.Colors.Text       = "000000";
            newAdUnit.CustomStyle.Colors.Title      = "000000";
            newAdUnit.CustomStyle.Colors.Url        = "0000ff";
            newAdUnit.CustomStyle.Corners           = "SQUARE";
            newAdUnit.CustomStyle.Font              = new AdStyle.FontData();
            newAdUnit.CustomStyle.Font.Family       = "ACCOUNT_DEFAULT_FAMILY";
            newAdUnit.CustomStyle.Font.Size         = "ACCOUNT_DEFAULT_SIZE";

            // Create ad unit.
            AccountsResource.AdunitsResource.InsertRequest insertRequest = this.service.Accounts.Adunits
                                                                           .Insert(newAdUnit, accountId, adClientId);

            AdUnit adUnit = insertRequest.Execute();

            Console.WriteLine("Ad unit of type {0}, name {1} and status {2} was created",
                              adUnit.ContentAdsSettings.Type, adUnit.Name, adUnit.Status);

            Console.WriteLine();

            // Return the Ad Unit that was just created
            return(adUnit);
        }
コード例 #21
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 InventoryService.
      InventoryService inventoryService =
          (InventoryService) user.GetService(DfpService.v201508.InventoryService);

      // Get the NetworkService.
      NetworkService networkService =
          (NetworkService) user.GetService(DfpService.v201508.NetworkService);

      // Set the parent ad unit's ID for all ad units to be created under.
      String effectiveRootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId;

      // Create local ad unit object.
      AdUnit adUnit = new AdUnit();
      adUnit.name = "Mobile_Ad_Unit";
      adUnit.parentId = effectiveRootAdUnitId;
      adUnit.description = "Ad unit description.";
      adUnit.targetWindow = AdUnitTargetWindow.BLANK;
      adUnit.targetPlatform = TargetPlatform.MOBILE;

      // Create ad unit size.
      AdUnitSize adUnitSize = new AdUnitSize();
      Size size = new Size();
      size.width = 400;
      size.height = 300;
      size.isAspectRatio = false;
      adUnitSize.size = size;
      adUnitSize.environmentType = EnvironmentType.BROWSER;

      // Set the size of possible creatives that can match this ad unit.
      adUnit.adUnitSizes = new AdUnitSize[] {adUnitSize};

      try {
        // Create the ad unit on the server.
        AdUnit[] createdAdUnits = inventoryService.createAdUnits(new AdUnit[] {adUnit});

        foreach (AdUnit createdAdunit in createdAdUnits) {
          Console.WriteLine("An ad unit with ID \"{0}\" was created under parent with ID " +
              "\"{1}\".", createdAdunit.id, createdAdunit.parentId);
        }
      } catch (Exception e) {
        Console.WriteLine("Failed to create ad units. Exception says \"{0}\"", e.Message);
      }
    }
コード例 #22
0
        /// <summary>
        /// Defines an ad unit in publisher tags without creating the container on the page.
        /// </summary>
        /// <param name="unitName">Name of the ad unit as set in DFP.</param>
        /// <param name="size">Ad unit size.</param>
        /// <param name="id">ID of the ad unit container.</param>
        public static void DefineAdUnit(string unitName, string size, string id)
        {
            if (String.IsNullOrWhiteSpace(unitName))
            {
                throw new ArgumentNullException("unitName");
            }
            if (String.IsNullOrWhiteSpace(id))
            {
                throw new ArgumentNullException("id");
            }

            var unit = new AdUnit
            {
                UnitName = unitName,
                Size     = size,
                Display  = false,
                Id       = id
            };


            AdUnits.Add(unit);
        }
コード例 #23
0
        public AdUnit CreateAdUnit(DfpUser user)
        {
            InventoryService inventoryService =
              (InventoryService) user.GetService(DfpService.v201511.InventoryService);

              AdUnit adUnit = new AdUnit();
              adUnit.name = string.Format("Ad_Unit_{0}", GetTimeStamp());
              adUnit.parentId = FindRootAdUnit(user).id;

              // Set the size of possible creatives that can match this ad unit.
              Size size = new Size();
              size.width = 300;
              size.height = 250;

              // Create ad unit size.
              AdUnitSize adUnitSize = new AdUnitSize();
              adUnitSize.size = size;
              adUnitSize.environmentType = EnvironmentType.BROWSER;

              adUnit.adUnitSizes = new AdUnitSize[] {adUnitSize};
              return inventoryService.createAdUnits(new AdUnit[] {adUnit})[0];
        }
        /// <summary>This example updates an ad unit on a publisher ad client.</summary>
        /// <param name="accountId">The ID for the publisher account to be used.</param>
        /// <param name="adClientId">An arbitrary publisher ad client ID.</param>
        /// <param name="adUnitId">The ID of the ad unit to be updated.</param>
        /// <returns>The updated custom channel.</returns>
        private AdUnit UpdateAdUnit(string accountId, string adClientId, string adUnitId)
        {
            Console.WriteLine("=================================================================");
            Console.WriteLine("Updating ad unit {0}", adUnitId);
            Console.WriteLine("=================================================================");

            AdUnit patchAdUnit = new AdUnit();

            patchAdUnit.CustomStyle             = new AdStyle();
            patchAdUnit.CustomStyle.Colors      = new AdStyle.ColorsData();
            patchAdUnit.CustomStyle.Colors.Text = "ff0000";

            // Update custom channel: Using REST's PATCH method to update just the Name field.
            AdUnit adUnit = this.service.Accounts.Adunits
                            .Patch(patchAdUnit, accountId, adClientId, adUnitId).Execute();

            Console.WriteLine("Ad unit with id {0}, was updated with text color {1}.",
                              adUnit.Id, adUnit.CustomStyle.Colors.Text);

            Console.WriteLine();

            // Return the Ad Unit that was just created
            return(adUnit);
        }
コード例 #25
0
        /// <summary>
        /// Run the sample code.
        /// </summary>
        public void Run(DfpUser user)
        {
            // Get the InventoryService.
            InventoryService inventoryService =
                (InventoryService)user.GetService(DfpService.v201608.InventoryService);

            // Set the ID of the ad unit to update.
            int adUnitId = int.Parse(_T("INSERT_AD_UNIT_ID_HERE"));

            // Create a statement to get the ad unit.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("id = :id")
                                                .OrderBy("id ASC")
                                                .Limit(1)
                                                .AddValue("id", adUnitId);

            try {
                // Get ad units by statement.
                AdUnitPage page = inventoryService.getAdUnitsByStatement(statementBuilder.ToStatement());

                AdUnit adUnit = page.results[0];
                adUnit.inheritedAdSenseSettings.value.adSenseEnabled = true;

                // Update the ad units on the server.
                AdUnit[] updatedAdUnits = inventoryService.updateAdUnits(new AdUnit[] { adUnit });

                foreach (AdUnit updatedAdUnit in updatedAdUnits)
                {
                    Console.WriteLine("Ad unit with ID \"{0}\", name \"{1}\", and is AdSense enabled " +
                                      "\"{2}\" was updated.", updatedAdUnit.id, updatedAdUnit.name,
                                      updatedAdUnit.inheritedAdSenseSettings.value.adSenseEnabled);
                }
            } catch (Exception e) {
                Console.WriteLine("Failed to update ad units. Exception says \"{0}\"", e.Message);
            }
        }
コード例 #26
0
 /// <summary>
 /// Displays the ad unit tree beginning at the root ad unit.
 /// </summary>
 /// <param name="root">The root ad unit</param>
 /// <param name="treeMap">The map of id to list of ad units</param>
 private static void DisplayInventoryTree(AdUnit root, Dictionary<String,
     List<AdUnit>> treeMap) {
   DisplayInventoryTreeHelper(root, treeMap, 0);
 }
コード例 #27
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(AdManagerUser user)
        {
            using (InventoryService inventoryService = user.GetService <InventoryService>())
            {
                // Get the NetworkService.
                NetworkService networkService = user.GetService <NetworkService>();

                // Set the parent ad unit's ID for all ad units to be created under.
                String effectiveRootAdUnitId =
                    networkService.getCurrentNetwork().effectiveRootAdUnitId;

                // Create local ad unit object.
                AdUnit adUnit = new AdUnit();
                adUnit.name               = "Video_Ad_Unit";
                adUnit.parentId           = effectiveRootAdUnitId;
                adUnit.description        = "Ad unit description.";
                adUnit.targetWindow       = AdUnitTargetWindow.BLANK;
                adUnit.explicitlyTargeted = true;

                // Create master ad unit size.
                AdUnitSize masterAdUnitSize = new AdUnitSize();
                Size       size1            = new Size();
                size1.width                      = 400;
                size1.height                     = 300;
                size1.isAspectRatio              = false;
                masterAdUnitSize.size            = size1;
                masterAdUnitSize.environmentType = EnvironmentType.VIDEO_PLAYER;

                // Create companion sizes.
                AdUnitSize companionAdUnitSize1 = new AdUnitSize();
                Size       size2 = new Size();
                size2.width                          = 300;
                size2.height                         = 250;
                size2.isAspectRatio                  = false;
                companionAdUnitSize1.size            = size2;
                companionAdUnitSize1.environmentType = EnvironmentType.BROWSER;

                AdUnitSize companionAdUnitSize2 = new AdUnitSize();
                Size       size3 = new Size();
                size3.width                          = 728;
                size3.height                         = 90;
                size3.isAspectRatio                  = false;
                companionAdUnitSize2.size            = size3;
                companionAdUnitSize2.environmentType = EnvironmentType.BROWSER;

                // Add companions to master ad unit size.
                masterAdUnitSize.companions = new AdUnitSize[]
                {
                    companionAdUnitSize1,
                    companionAdUnitSize2
                };

                // Set the size of possible creatives that can match this ad unit.
                adUnit.adUnitSizes = new AdUnitSize[]
                {
                    masterAdUnitSize
                };

                try
                {
                    // Create the ad unit on the server.
                    AdUnit[] createdAdUnits = inventoryService.createAdUnits(new AdUnit[]
                    {
                        adUnit
                    });

                    foreach (AdUnit createdAdUnit in createdAdUnits)
                    {
                        Console.WriteLine(
                            "A video ad unit with ID \"{0}\" was created under parent with ID " +
                            "\"{1}\".", createdAdUnit.id, createdAdUnit.parentId);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to create video ad units. Exception says \"{0}\"",
                                      e.Message);
                }
            }
        }
コード例 #28
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 InventoryService.
            InventoryService inventoryService =
                (InventoryService)user.GetService(DfpService.v201311.InventoryService);

            // Get the NetworkService.
            NetworkService networkService =
                (NetworkService)user.GetService(DfpService.v201311.NetworkService);

            // Set the parent ad unit's ID for all ad units to be created under.
            String effectiveRootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId;

            // Create local ad unit object.
            AdUnit adUnit = new AdUnit();

            adUnit.name               = "Video_Ad_Unit";
            adUnit.parentId           = effectiveRootAdUnitId;
            adUnit.description        = "Ad unit description.";
            adUnit.targetWindow       = AdUnitTargetWindow.BLANK;
            adUnit.explicitlyTargeted = true;
            adUnit.targetPlatform     = TargetPlatform.WEB;

            // Create master ad unit size.
            AdUnitSize masterAdUnitSize = new AdUnitSize();
            Size       size1            = new Size();

            size1.width                      = 400;
            size1.height                     = 300;
            size1.isAspectRatio              = false;
            masterAdUnitSize.size            = size1;
            masterAdUnitSize.environmentType = EnvironmentType.VIDEO_PLAYER;

            // Create companion sizes.
            AdUnitSize companionAdUnitSize1 = new AdUnitSize();
            Size       size2 = new Size();

            size2.width                          = 300;
            size2.height                         = 250;
            size2.isAspectRatio                  = false;
            companionAdUnitSize1.size            = size2;
            companionAdUnitSize1.environmentType = EnvironmentType.BROWSER;

            AdUnitSize companionAdUnitSize2 = new AdUnitSize();
            Size       size3 = new Size();

            size3.width                          = 728;
            size3.height                         = 90;
            size3.isAspectRatio                  = false;
            companionAdUnitSize2.size            = size3;
            companionAdUnitSize2.environmentType = EnvironmentType.BROWSER;

            // Add companions to master ad unit size.
            masterAdUnitSize.companions = new AdUnitSize[] { companionAdUnitSize1, companionAdUnitSize2 };

            // Set the size of possible creatives that can match this ad unit.
            adUnit.adUnitSizes = new AdUnitSize[] { masterAdUnitSize };

            try {
                // Create the ad unit on the server.
                adUnit = inventoryService.createAdUnit(adUnit);

                if (adUnit != null)
                {
                    Console.WriteLine("A video ad unit with ID \"{0}\" was created under parent with ID " +
                                      "\"{1}\".", adUnit.id, adUnit.parentId);
                }
                else
                {
                    Console.WriteLine("No video ad units created.");
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to create video ad units. Exception says \"{0}\"", ex.Message);
            }
        }
コード例 #29
0
 public void Init() {
   TestUtils utils = new TestUtils();
   inventoryService = (InventoryService) user.GetService(DfpService.v201511.InventoryService);
   adUnit1 = utils.CreateAdUnit(user);
   adUnit2 = utils.CreateAdUnit(user);
 }
コード例 #30
0
        /// <summary>This example updates an ad unit on a publisher ad client.</summary>
        /// <param name="accountId">The ID for the publisher account to be used.</param>
        /// <param name="adClientId">An arbitrary publisher ad client ID.</param>
        /// <param name="adUnitId">The ID of the ad unit to be updated.</param>
        /// <returns>The updated custom channel.</returns>
        private AdUnit UpdateAdUnit(string accountId, string adClientId, string adUnitId)
        {
            Console.WriteLine("=================================================================");
            Console.WriteLine("Updating ad unit {0}", adUnitId);
            Console.WriteLine("=================================================================");

            AdUnit patchAdUnit = new AdUnit();
            patchAdUnit.CustomStyle = new AdStyle();
            patchAdUnit.CustomStyle.Colors = new AdStyle.ColorsData();
            patchAdUnit.CustomStyle.Colors.Text = "ff0000";

            // Update custom channel: Using REST's PATCH method to update just the Name field.
            AdUnit adUnit = this.service.Accounts.Adunits
                .Patch(patchAdUnit, accountId, adClientId, adUnitId).Execute();

            Console.WriteLine("Ad unit with id {0}, was updated with text color {1}.",
                adUnit.Id, adUnit.CustomStyle.Colors.Text);

            Console.WriteLine();

            // Return the Ad Unit that was just created
            return adUnit;
        }
コード例 #31
0
        /// <summary>This example adds a new ad unit to a publisher ad client.</summary>
        /// <param name="accountId">The ID for the publisher account to be used.</param>
        /// <param name="adClientId">An arbitrary publisher ad client ID.</param>
        /// <returns>The created ad unit.</returns>
        private AdUnit AddAdUnit(string accountId, string adClientId)
        {
            Console.WriteLine("=================================================================");
            Console.WriteLine("Adding ad unit to ad client {0}", accountId);
            Console.WriteLine("=================================================================");

            AdUnit newAdUnit = new AdUnit();

            Random random = new Random(DateTime.Now.Millisecond);
            newAdUnit.Name = "Ad Unit #"
                + random.Next(0, 10000).ToString();

            newAdUnit.ContentAdsSettings = new AdUnit.ContentAdsSettingsData();
            newAdUnit.ContentAdsSettings.BackupOption = new AdUnit.ContentAdsSettingsData.BackupOptionData();

            newAdUnit.ContentAdsSettings.BackupOption.Type = "COLOR";
            newAdUnit.ContentAdsSettings.BackupOption.Color = "ffffff";
            newAdUnit.ContentAdsSettings.Size = "SIZE_200_200";
            newAdUnit.ContentAdsSettings.Type = "TEXT";
            newAdUnit.CustomStyle = new AdStyle();
            newAdUnit.CustomStyle.Colors = new AdStyle.ColorsData();
            newAdUnit.CustomStyle.Colors.Background = "ffffff";
            newAdUnit.CustomStyle.Colors.Border = "000000";
            newAdUnit.CustomStyle.Colors.Text = "000000";
            newAdUnit.CustomStyle.Colors.Title = "000000";
            newAdUnit.CustomStyle.Colors.Url = "0000ff";
            newAdUnit.CustomStyle.Corners = "SQUARE";
            newAdUnit.CustomStyle.Font = new AdStyle.FontData();
            newAdUnit.CustomStyle.Font.Family = "ACCOUNT_DEFAULT_FAMILY";
            newAdUnit.CustomStyle.Font.Size = "ACCOUNT_DEFAULT_SIZE";

            // Create ad unit.
            AccountsResource.AdunitsResource.InsertRequest insertRequest = this.service.Accounts.Adunits
                .Insert(newAdUnit, accountId, adClientId);

            AdUnit adUnit = insertRequest.Execute();

            Console.WriteLine("Ad unit of type {0}, name {1} and status {2} was created",
                adUnit.ContentAdsSettings.Type, adUnit.Name, adUnit.Status);

            Console.WriteLine();

            // Return the Ad Unit that was just created
            return adUnit;
        }
コード例 #32
0
    /// <summary>
    /// Builds and displays an ad unit tree from an array of ad units underneath
    /// the root ad unit.
    /// </summary>
    /// <param name="root">The root ad unit to build the tree under.</param>
    /// <param name="units">The array of ad units.</param>
    private static void BuildAndDisplayAdUnitTree(AdUnit root, AdUnit[] units) {
      Dictionary<String, List<AdUnit>> treeMap = new Dictionary<String, List<AdUnit>>();

      foreach (AdUnit unit in units) {
        if (unit.parentId != null) {
          if (treeMap.ContainsKey(unit.parentId) == false) {
            treeMap.Add(unit.parentId, new List<AdUnit>());
          }
          treeMap[unit.parentId].Add(unit);
        }
      }

      if (root != null) {
        DisplayInventoryTree(root, treeMap);
      } else {
        Console.WriteLine("No root unit found.");
      }
    }
コード例 #33
0
 /// <summary>
 /// Displays the ad unit tree beginning at the root ad unit.
 /// </summary>
 /// <param name="root">The root ad unit</param>
 /// <param name="treeMap">The map of id to list of ad units</param>
 private static void DisplayInventoryTree(AdUnit root, Dictionary <String,
                                                                   List <AdUnit> > treeMap)
 {
     DisplayInventoryTreeHelper(root, treeMap, 0);
 }
コード例 #34
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 InventoryService.
      InventoryService inventoryService =
          (InventoryService) user.GetService(DfpService.v201508.InventoryService);

      // Get the NetworkService.
      NetworkService networkService =
          (NetworkService) user.GetService(DfpService.v201508.NetworkService);

      // Set the parent ad unit's ID for all ad units to be created under.
      String effectiveRootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId;

      // Create local ad unit object.
      AdUnit adUnit = new AdUnit();
      adUnit.name = "Video_Ad_Unit";
      adUnit.parentId = effectiveRootAdUnitId;
      adUnit.description = "Ad unit description.";
      adUnit.targetWindow = AdUnitTargetWindow.BLANK;
      adUnit.explicitlyTargeted = true;
      adUnit.targetPlatform = TargetPlatform.WEB;

      // Create master ad unit size.
      AdUnitSize masterAdUnitSize = new AdUnitSize();
      Size size1 = new Size();
      size1.width = 400;
      size1.height = 300;
      size1.isAspectRatio = false;
      masterAdUnitSize.size = size1;
      masterAdUnitSize.environmentType = EnvironmentType.VIDEO_PLAYER;

      // Create companion sizes.
      AdUnitSize companionAdUnitSize1 = new AdUnitSize();
      Size size2 = new Size();
      size2.width = 300;
      size2.height = 250;
      size2.isAspectRatio = false;
      companionAdUnitSize1.size = size2;
      companionAdUnitSize1.environmentType = EnvironmentType.BROWSER;

      AdUnitSize companionAdUnitSize2 = new AdUnitSize();
      Size size3 = new Size();
      size3.width = 728;
      size3.height = 90;
      size3.isAspectRatio = false;
      companionAdUnitSize2.size = size3;
      companionAdUnitSize2.environmentType = EnvironmentType.BROWSER;

      // Add companions to master ad unit size.
      masterAdUnitSize.companions = new AdUnitSize[] {companionAdUnitSize1, companionAdUnitSize2};

      // Set the size of possible creatives that can match this ad unit.
      adUnit.adUnitSizes = new AdUnitSize[] {masterAdUnitSize};

      try {
        // Create the ad unit on the server.
        AdUnit[] createdAdUnits = inventoryService.createAdUnits(new AdUnit[] {adUnit});

        foreach (AdUnit createdAdUnit in createdAdUnits) {
          Console.WriteLine("A video ad unit with ID \"{0}\" was created under parent with ID " +
              "\"{1}\".", createdAdUnit.id, createdAdUnit.parentId);
        }
      } catch (Exception e) {
        Console.WriteLine("Failed to create video ad units. Exception says \"{0}\"", e.Message);
      }
    }
コード例 #35
0
    /// <summary>
    /// Helper for displaying inventory units.
    /// </summary>
    /// <param name="root">The root inventory unit.</param>
    /// <param name="treeMap">The map of id to List of inventory units.</param>
    /// <param name="depth">The depth the tree has reached.</param>
    private static void DisplayInventoryTreeHelper(AdUnit root,
        Dictionary<String, List<AdUnit>> treeMap, int depth) {
      Console.WriteLine(GenerateTab(depth) + root.name + " (" + root.id + ")");

      if (treeMap.ContainsKey(root.id)) {
        foreach (AdUnit child in treeMap[root.id]) {
          DisplayInventoryTreeHelper(child, treeMap, depth + 1);
        }
      }
    }
コード例 #36
0
        /// <summary>
        /// Update the supplied ad unit in the specified publisher AdSense account.
        /// Documentation https://developers.google.com/adsensehost/v4.1/reference/adunits/update
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated AdSenseHost service.</param>
        /// <param name="accountId">Account which contains the ad client.</param>
        /// <param name="adClientId">Ad client which contains the ad unit.</param>
        /// <param name="body">A valid AdSenseHost v4.1 body.</param>
        /// <returns>AdUnitResponse</returns>
        public static AdUnit Update(AdSenseHostService service, string accountId, string adClientId, AdUnit body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (accountId == null)
                {
                    throw new ArgumentNullException(accountId);
                }
                if (adClientId == null)
                {
                    throw new ArgumentNullException(adClientId);
                }

                // Make the request.
                return(service.Adunits.Update(body, accountId, adClientId).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Adunits.Update failed.", ex);
            }
        }