Exemple #1
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="service">An initialized Dfa Reporting service object
        /// </param>
        public override void Run(DfareportingService service)
        {
            long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE"));
            long profileId    = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE"));

            string videoAssetName       = _T("INSERT_VIDEO_ASSET_NAME_HERE");
            string pathToVideoAssetFile = _T("INSERT_PATH_TO_VIDEO_ASSET_FILE_HERE");

            Creative creative = new Creative();

            creative.AdvertiserId = advertiserId;
            creative.Name         = "Test in-stream video creative";
            creative.Type         = "INSTREAM_VIDEO";

            // Upload the video asset.
            CreativeAssetUtils assetUtils   = new CreativeAssetUtils(service, profileId, advertiserId);
            CreativeAssetId    videoAssetId = assetUtils.uploadAsset(pathToVideoAssetFile, "VIDEO");

            CreativeAsset videoAsset = new CreativeAsset();

            videoAsset.AssetIdentifier = videoAssetId;
            videoAsset.Role            = "PARENT_VIDEO";

            // Add the creative assets.
            creative.CreativeAssets = new List <CreativeAsset>()
            {
                videoAsset
            };

            Creative result = service.Creatives.Insert(creative, profileId).Execute();

            // Display the new creative ID.
            Console.WriteLine("In-stream video creative with ID {0} was created.", result.Id);
        }
Exemple #2
0
        /// <summary>
        /// Create a test company for running further tests.
        /// </summary>
        /// <returns>A creative for running further tests.</returns>
        public Creative CreateCreative(DfpUser user, long advertiserId)
        {
            CreativeService creativeService = (CreativeService)user.GetService(
                DfpService.v201411.CreativeService);

            // Create creative size.
            Size size = new Size();

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

            // Create an image creative.
            ImageCreative imageCreative = new ImageCreative();

            imageCreative.name           = string.Format("Image creative #{0}", GetTimeStamp());
            imageCreative.advertiserId   = advertiserId;
            imageCreative.destinationUrl = "http://www.google.com";
            imageCreative.size           = size;

            // Create image asset.
            CreativeAsset creativeAsset = new CreativeAsset();

            creativeAsset.fileName       = "image.jpg";
            creativeAsset.assetByteArray = MediaUtilities.GetAssetDataFromUrl(
                "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg");
            creativeAsset.size = size;
            imageCreative.primaryImageAsset = creativeAsset;

            return(creativeService.createCreatives(new Creative[] { imageCreative })[0]);
        }
Exemple #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)
        {
            // Get the CreativeService.
            CreativeService creativeService =
                (CreativeService)user.GetService(DfpService.v201605.CreativeService);

            // Set the ID of the advertiser (company) that all creatives will be
            // assigned to.
            long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE"));

            // Create the local custom creative object.
            CustomCreative customCreative = new CustomCreative();

            customCreative.name           = "Custom creative " + GetTimeStamp();
            customCreative.advertiserId   = advertiserId;
            customCreative.destinationUrl = "http://google.com";

            // Set the custom creative image asset.
            CustomCreativeAsset customCreativeAsset = new CustomCreativeAsset();

            customCreativeAsset.macroName = "IMAGE_ASSET";
            CreativeAsset asset = new CreativeAsset();

            asset.fileName       = string.Format("inline{0}.jpg", GetTimeStamp());
            asset.assetByteArray = MediaUtilities.GetAssetDataFromUrl(
                "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg");
            customCreativeAsset.asset = asset;

            customCreative.customCreativeAssets = new CustomCreativeAsset[] { customCreativeAsset };

            // Set the HTML snippet using the custom creative asset macro.
            customCreative.htmlSnippet = "<a href='%%CLICK_URL_UNESC%%%%DEST_URL%%'>" +
                                         "<img src='%%FILE:" + customCreativeAsset.macroName + "%%'/>" +
                                         "</a><br>Click above for great deals!";

            // Set the creative size.
            Size size = new Size();

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

            customCreative.size = size;

            try {
                // Create the custom creative on the server.
                Creative[] createdCreatives = creativeService.createCreatives(
                    new Creative[] { customCreative });

                foreach (Creative createdCreative in createdCreatives)
                {
                    Console.WriteLine("A custom creative with ID \"{0}\", name \"{1}\", and size ({2}, " +
                                      "{3}) was created and can be previewed at {4}", createdCreative.id,
                                      createdCreative.name, createdCreative.size.width, createdCreative.size.height,
                                      createdCreative.previewUrl);
                }
            } catch (Exception e) {
                Console.WriteLine("Failed to create custom creatives. Exception says \"{0}\"", e.Message);
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The Dfa user object running the code example.
        /// </param>
        public override void Run(DfaUser user)
        {
            // Create CreateRemoteService instance.
            CreativeRemoteService service = (CreativeRemoteService)user.GetService(
                DfaService.v1_20.CreativeRemoteService);

            long   advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE"));
            string assetName    = _T("INSERT_MOBILE_ASSET_NAME_HERE");
            string pathToFile   = _T("INSERT_PATH_TO_MOBILE_ASSET_HERE");

            // Set mobile asset structure.
            CreativeAsset mobileAsset = new CreativeAsset();

            mobileAsset.forHTMLCreatives = true;
            mobileAsset.advertiserId     = advertiserId;
            mobileAsset.content          = MediaUtilities.GetAssetDataFromUrl(new Uri(pathToFile));
            mobileAsset.name             = assetName;

            try {
                // Create mobile asset.
                CreativeAssetSaveResult result = service.saveCreativeAsset(mobileAsset);

                // Display asset file name.
                Console.WriteLine("Asset was saved with file name of \"{0}\".", result.savedFilename);
            } catch (Exception ex) {
                Console.WriteLine("Failed to create mobile asset. Exception says \"{0}\"", ex.Message);
            }
        }
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="service">An initialized Dfa Reporting service object
    /// </param>
    public override void Run(DfareportingService service) {
      long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE"));
      long sizeId = long.Parse(_T("INSERT_SIZE_ID_HERE"));
      long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE"));

      string pathToImageAssetFile = _T("INSERT_PATH_TO_IMAGE_ASSET_FILE_HERE");

      Creative creative = new Creative();
      creative.AdvertiserId = advertiserId;
      creative.Name = "Test image creative";
      creative.Size = new Size() { Id = sizeId };
      creative.Type = "IMAGE";

      // Upload the image asset.
      CreativeAssetUtils assetUtils = new CreativeAssetUtils(service, profileId, advertiserId);
      CreativeAssetId imageAssetId = assetUtils.uploadAsset(pathToImageAssetFile, "IMAGE");

      CreativeAsset imageAsset = new CreativeAsset();
      imageAsset.AssetIdentifier = imageAssetId;
      imageAsset.Role = "PRIMARY";

      // Add the creative assets.
      creative.CreativeAssets = new List<CreativeAsset>() { imageAsset };

      Creative result = service.Creatives.Insert(creative, profileId).Execute();

      // Display the new creative ID.
      Console.WriteLine("Image creative with ID {0} was created.", result.Id);
    }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="service">An initialized Dfa Reporting service object
        /// </param>
        public override void Run(DfareportingService service)
        {
            long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE"));
              long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE"));

              string videoAssetName = _T("INSERT_VIDEO_ASSET_NAME_HERE");
              string pathToVideoAssetFile = _T("INSERT_PATH_TO_VIDEO_ASSET_FILE_HERE");

              Creative creative = new Creative();
              creative.AdvertiserId = advertiserId;
              creative.Name = "Test in-stream video creative";
              creative.Type = "INSTREAM_VIDEO";

              // Upload the video asset.
              CreativeAssetUtils assetUtils = new CreativeAssetUtils(service, profileId, advertiserId);
              CreativeAssetId videoAssetId = assetUtils.uploadAsset(pathToVideoAssetFile, "VIDEO");

              CreativeAsset videoAsset = new CreativeAsset();
              videoAsset.AssetIdentifier = videoAssetId;
              videoAsset.Role = "PARENT_VIDEO";

              // Add the creative assets.
              creative.CreativeAssets = new List<CreativeAsset>() { videoAsset };

              Creative result = service.Creatives.Insert(creative, profileId).Execute();

              // Display the new creative ID.
              Console.WriteLine("In-stream video creative with ID {0} was created.", result.Id);
        }
Exemple #7
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="service">An initialized Dfa Reporting service object
        /// </param>
        public override void Run(DfareportingService service)
        {
            long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE"));
            long sizeId       = long.Parse(_T("INSERT_SIZE_ID_HERE"));
            long profileId    = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE"));

            string pathToHtml5AssetFile = _T("INSERT_PATH_TO_HTML5_ASSET_FILE_HERE");
            string pathToImageAssetFile = _T("INSERT_PATH_TO_IMAGE_ASSET_FILE_HERE");

            Creative creative = new Creative();

            creative.AdvertiserId = advertiserId;
            creative.Name         = "Test HTML5 banner creative";
            creative.Size         = new Size()
            {
                Id = sizeId
            };
            creative.Type = "HTML5_BANNER";

            // Upload the HTML5 asset.
            CreativeAssetUtils assetUtils   = new CreativeAssetUtils(service, profileId, advertiserId);
            CreativeAssetId    html5AssetId = assetUtils.uploadAsset(pathToHtml5AssetFile, "HTML");

            CreativeAsset html5Asset = new CreativeAsset();

            html5Asset.AssetIdentifier = html5AssetId;
            html5Asset.Role            = "PRIMARY";

            // Upload the backup image asset.
            CreativeAssetId imageAssetId = assetUtils.uploadAsset(pathToImageAssetFile, "HTML_IMAGE");

            CreativeAsset imageAsset = new CreativeAsset();

            imageAsset.AssetIdentifier = imageAssetId;
            imageAsset.Role            = "BACKUP_IMAGE";

            // Add the creative assets.
            creative.CreativeAssets = new List <CreativeAsset>()
            {
                html5Asset, imageAsset
            };

            // Add a click tag.
            ClickTag clickTag = new ClickTag()
            {
                Name = "clickTag"
            };

            creative.ClickTags = new List <ClickTag>()
            {
                clickTag
            };

            Creative result = service.Creatives.Insert(creative, profileId).Execute();

            // Display the new creative ID.
            Console.WriteLine("HTML5 banner creative with ID {0} was created.", result.Id);
        }
Exemple #8
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            using (CreativeService creativeService =
                       (CreativeService)user.GetService(DfpService.v201711.CreativeService)) {
                long creativeId = long.Parse(_T("INSERT_IMAGE_CREATIVE_ID_HERE"));

                // Create a statement to get the image creative.
                StatementBuilder statementBuilder = new StatementBuilder()
                                                    .Where("id = :id")
                                                    .OrderBy("id ASC")
                                                    .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                    .AddValue("id", creativeId);

                try {
                    // Get the creative.
                    CreativePage page = creativeService.getCreativesByStatement(
                        statementBuilder.ToStatement());

                    if (page.results != null)
                    {
                        ImageCreative imageCreative = (ImageCreative)page.results[0];
                        // Since we cannot set id to null, we mark it as not specified.
                        imageCreative.idSpecified = false;

                        imageCreative.advertiserId = imageCreative.advertiserId;
                        imageCreative.name         = imageCreative.name + " (Copy #" + GetTimeStamp() + ")";

                        // Create image asset.
                        CreativeAsset creativeAsset = new CreativeAsset();
                        creativeAsset.fileName       = "image.jpg";
                        creativeAsset.assetByteArray = MediaUtilities.GetAssetDataFromUrl(
                            imageCreative.primaryImageAsset.assetUrl);

                        creativeAsset.size = imageCreative.primaryImageAsset.size;
                        imageCreative.primaryImageAsset = creativeAsset;

                        // Create the copied creative.
                        Creative[] creatives = creativeService.createCreatives(
                            new Creative[] { imageCreative });

                        // Display copied creatives.
                        foreach (Creative copiedCreative in creatives)
                        {
                            Console.WriteLine("Image creative with ID \"{0}\", name \"{1}\", and type \"{2}\" " +
                                              "was created and can be previewed at {3}", copiedCreative.id,
                                              copiedCreative.name, copiedCreative.GetType().Name, copiedCreative.previewUrl);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No creatives were copied.");
                    }
                } catch (Exception e) {
                    Console.WriteLine("Failed to copy creatives. Exception says \"{0}\"", e.Message);
                }
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="service">An initialized Dfa Reporting service object
        /// </param>
        public override void Run(DfareportingService service)
        {
            long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE"));
            long sizeId       = long.Parse(_T("INSERT_SIZE_ID_HERE"));
            long profileId    = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE"));

            string pathToFlashAssetFile = _T("INSERT_PATH_TO_FLASH_ASSET_FILE_HERE");
            string pathToImageAssetFile = _T("INSERT_PATH_TO_IMAGE_ASSET_FILE_HERE");

            Creative creative = new Creative();

            creative.AdvertiserId = advertiserId;
            creative.Name         = "Test flash display creative";
            creative.Size         = new Size()
            {
                Id = sizeId
            };
            creative.Type = "ENHANCED_BANNER";

            // Upload the flash asset.
            CreativeAssetUtils assetUtils   = new CreativeAssetUtils(service, profileId, advertiserId);
            CreativeAssetId    flashAssetId = assetUtils.uploadAsset(pathToFlashAssetFile, "FLASH");

            CreativeAsset flashAsset = new CreativeAsset();

            flashAsset.AssetIdentifier = flashAssetId;
            flashAsset.Role            = "PRIMARY";
            flashAsset.WindowMode      = "TRANSPARENT";

            // Upload the backup image asset.
            CreativeAssetId imageAssetId = assetUtils.uploadAsset(pathToImageAssetFile, "HTML_IMAGE");

            CreativeAsset imageAsset = new CreativeAsset();

            imageAsset.AssetIdentifier = imageAssetId;
            imageAsset.Role            = "BACKUP_IMAGE";

            // Add the creative assets.
            creative.CreativeAssets = new List <CreativeAsset>()
            {
                flashAsset, imageAsset
            };

            // Configure the backup image.
            creative.BackupImageClickThroughUrl = "https://www.google.com";
            creative.BackupImageReportingLabel  = "backup";
            creative.BackupImageTargetWindow    = new TargetWindow()
            {
                TargetWindowOption = "NEW_WINDOW"
            };

            Creative result = service.Creatives.Insert(creative, profileId).Execute();

            // Display the new creative ID.
            Console.WriteLine("Flash display creative with ID {0} was created.", result.Id);
        }
    /// <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 CreativeService.
      CreativeService creativeService =
          (CreativeService) user.GetService(DfpService.v201511.CreativeService);

      // Set the ID of the advertiser (company) that all creatives will be
      // assigned to.
      long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE"));

      // Create the local custom creative object.
      CustomCreative customCreative = new CustomCreative();
      customCreative.name = "Custom creative " + GetTimeStamp();
      customCreative.advertiserId = advertiserId;
      customCreative.destinationUrl = "http://google.com";

      // Set the custom creative image asset.
      CustomCreativeAsset customCreativeAsset = new CustomCreativeAsset();
      customCreativeAsset.macroName = "IMAGE_ASSET";
      CreativeAsset asset = new CreativeAsset();
      asset.fileName = string.Format("inline{0}.jpg", GetTimeStamp());
      asset.assetByteArray = MediaUtilities.GetAssetDataFromUrl(
          "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg");
      customCreativeAsset.asset = asset;

      customCreative.customCreativeAssets = new CustomCreativeAsset[] {customCreativeAsset};

      // Set the HTML snippet using the custom creative asset macro.
      customCreative.htmlSnippet = "<a href='%%CLICK_URL_UNESC%%%%DEST_URL%%'>" +
          "<img src='%%FILE:" + customCreativeAsset.macroName + "%%'/>" +
          "</a><br>Click above for great deals!";

      // Set the creative size.
      Size size = new Size();
      size.width = 300;
      size.height = 250;
      size.isAspectRatio = false;

      customCreative.size = size;

      try {
        // Create the custom creative on the server.
        Creative[] createdCreatives = creativeService.createCreatives(
            new Creative[] {customCreative});

        foreach (Creative createdCreative in createdCreatives) {
          Console.WriteLine("A custom creative with ID \"{0}\", name \"{1}\", and size ({2}, " +
              "{3}) was created and can be previewed at {4}", createdCreative.id,
              createdCreative.name, createdCreative.size.width, createdCreative.size.height,
              createdCreative.previewUrl);
        }
      } catch (Exception e) {
        Console.WriteLine("Failed to create custom creatives. Exception says \"{0}\"", e.Message);
      }
    }
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="service">An initialized Dfa Reporting service object
    /// </param>
    public override void Run(DfareportingService service) {
      long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE"));
      long sizeId = long.Parse(_T("INSERT_SIZE_ID_HERE"));
      long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE"));

      string pathToImageAssetFile = _T("INSERT_PATH_TO_IMAGE_ASSET_FILE_HERE");
      string pathToImageAsset2File = _T("INSERT_PATH_TO_IMAGE_ASSET_FILE_HERE");

      Creative creative = new Creative();
      creative.AdvertiserId = advertiserId;
      creative.AutoAdvanceImages = true;
      creative.Name = "Test enhanced image creative";
      creative.Size = new Size() { Id = sizeId };
      creative.Type = "ENHANCED_IMAGE";

      // Upload the first image asset.
      CreativeAssetUtils assetUtils = new CreativeAssetUtils(service, profileId, advertiserId);
      CreativeAssetId imageAsset1Id = assetUtils.uploadAsset(pathToImageAssetFile, "HTML_IMAGE");

      CreativeAsset imageAsset1 = new CreativeAsset();
      imageAsset1.AssetIdentifier = imageAsset1Id;
      imageAsset1.Role = "PRIMARY";

      // Upload the second image asset.
      CreativeAssetId imageAsset2Id = assetUtils.uploadAsset(pathToImageAsset2File, "HTML_IMAGE");

      CreativeAsset imageAsset2 = new CreativeAsset();
      imageAsset2.AssetIdentifier = imageAsset2Id;
      imageAsset2.Role = "PRIMARY";

      // Add the creative assets.
      creative.CreativeAssets = new List<CreativeAsset>() { imageAsset1, imageAsset2 };

      // Create a click tag for the first image asset.
      ClickTag clickTag1 = new ClickTag();
      clickTag1.Name = imageAsset1Id.Name;
      clickTag1.EventName = imageAsset1Id.Name;

      // Create a click tag for the second image asset.
      ClickTag clickTag2 = new ClickTag();
      clickTag2.Name = imageAsset2Id.Name;
      clickTag2.EventName = imageAsset2Id.Name;

      // Add the click tags.
      creative.ClickTags = new List<ClickTag>() { clickTag1, clickTag2 };

      Creative result = service.Creatives.Insert(creative, profileId).Execute();

      // Display the new creative ID.
      Console.WriteLine("Enhanced image creative with ID {0} was created.", result.Id);
    }
    /// <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 CreativeService.
      CreativeService creativeService =
          (CreativeService) user.GetService(DfpService.v201511.CreativeService);

      long creativeId = long.Parse(_T("INSERT_IMAGE_CREATIVE_ID_HERE"));

      // Create a statement to get the image creative.
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("id = :id")
          .OrderBy("id ASC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .AddValue("id", creativeId);

      try {
        // Get the creative.
        CreativePage page = creativeService.getCreativesByStatement(statementBuilder.ToStatement());

        if (page.results != null) {
          ImageCreative imageCreative = (ImageCreative) page.results[0];
          // Since we cannot set id to null, we mark it as not specified.
          imageCreative.idSpecified = false;

          imageCreative.advertiserId = imageCreative.advertiserId;
          imageCreative.name = imageCreative.name + " (Copy #" + GetTimeStamp() + ")";

          // Create image asset.
          CreativeAsset creativeAsset = new CreativeAsset();
          creativeAsset.fileName = "image.jpg";
          creativeAsset.assetByteArray = MediaUtilities.GetAssetDataFromUrl(
              imageCreative.primaryImageAsset.assetUrl);

          creativeAsset.size = imageCreative.primaryImageAsset.size;
          imageCreative.primaryImageAsset = creativeAsset;

          // Create the copied creative.
          Creative[] creatives = creativeService.createCreatives(new Creative[] {imageCreative});

          // Display copied creatives.
          foreach (Creative copiedCreative in creatives) {
            Console.WriteLine("Image creative with ID \"{0}\", name \"{1}\", and type \"{2}\" " +
                "was created and can be previewed at {3}", copiedCreative.id, copiedCreative.name,
                 copiedCreative.GetType().Name, copiedCreative.previewUrl);
          }
        } else {
          Console.WriteLine("No creatives were copied.");
        }
      } catch (Exception e) {
        Console.WriteLine("Failed to copy creatives. Exception says \"{0}\"", e.Message);
      }
    }
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="service">An initialized Dfa Reporting service object
    /// </param>
    public override void Run(DfareportingService service) {
      long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE"));
      long sizeId = long.Parse(_T("INSERT_SIZE_ID_HERE"));
      long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE"));

      string pathToHtmlAssetFile = _T("INSERT_PATH_TO_HTML_ASSET_FILE_HERE");
      string pathToImageAssetFile = _T("INSERT_PATH_TO_IMAGE_ASSET_FILE_HERE");

      Creative creative = new Creative();
      creative.AdvertiserId = advertiserId;
      creative.Name = "Test enhanced banner creative";
      creative.Size = new Size() { Id = sizeId };
      creative.Type = "ENHANCED_BANNER";

      // Upload the HTML asset.
      CreativeAssetUtils assetUtils = new CreativeAssetUtils(service, profileId, advertiserId);
      CreativeAssetId htmlAssetId = assetUtils.uploadAsset(pathToHtmlAssetFile, "HTML");

      CreativeAsset htmlAsset = new CreativeAsset();
      htmlAsset.AssetIdentifier = htmlAssetId;
      htmlAsset.Role = "PRIMARY";
      htmlAsset.WindowMode = "TRANSPARENT";

      // Upload the backup image asset.
      CreativeAssetId backupImageAssetId =
          assetUtils.uploadAsset(pathToImageAssetFile, "HTML_IMAGE");

      CreativeAsset backupImageAsset = new CreativeAsset();
      backupImageAsset.AssetIdentifier = backupImageAssetId;
      backupImageAsset.Role = "BACKUP_IMAGE";

      // Add the creative assets.
      creative.CreativeAssets = new List<CreativeAsset>() { htmlAsset, backupImageAsset };

      // Configure the backup image.
      creative.BackupImageClickThroughUrl = "https://www.google.com";
      creative.BackupImageReportingLabel = "backup";
      creative.BackupImageTargetWindow = new TargetWindow() { TargetWindowOption = "NEW_WINDOW" };

      // Add a click tag.
      ClickTag clickTag = new ClickTag();
      clickTag.Name = "clickTag";
      clickTag.EventName = "exit";
      clickTag.Value = "https://www.google.com";
      creative.ClickTags = new List<ClickTag>() { clickTag };

      Creative result = service.Creatives.Insert(creative, profileId).Execute();

      // Display the new creative ID.
      Console.WriteLine("Enhanced banner creative with ID {0} was created.", result.Id);
    }
        public void TestCreateCreatives()
        {
            // Create an array to store local image creative objects.
            Creative[] imageCreatives = new ImageCreative[2];

            for (int i = 0; i < 2; i++)
            {
                // Create creative size.
                Size size = new Size();
                size.width  = 300;
                size.height = 250;

                // Create an image creative.
                ImageCreative imageCreative = new ImageCreative();
                imageCreative.name           = string.Format("Image creative #{0}", i);
                imageCreative.advertiserId   = advertiserId;
                imageCreative.destinationUrl = "http://www.google.com";
                imageCreative.size           = size;

                // Create image asset.
                CreativeAsset creativeAsset = new CreativeAsset();
                creativeAsset.fileName       = "image.jpg";
                creativeAsset.assetByteArray = MediaUtilities.GetAssetDataFromUrl(
                    "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg");
                creativeAsset.size = size;
                imageCreative.primaryImageAsset = creativeAsset;

                imageCreatives[i] = imageCreative;
            }

            Creative[] newCreatives = null;

            Assert.DoesNotThrow(delegate() {
                newCreatives = creativeService.createCreatives(imageCreatives);
            });

            Assert.NotNull(newCreatives);
            Assert.AreEqual(newCreatives.Length, 2);
            Assert.NotNull(newCreatives[0]);
            Assert.That(newCreatives[0] is ImageCreative);
            Assert.AreEqual(newCreatives[0].advertiserId, advertiserId);
            Assert.AreEqual(newCreatives[0].name, "Image creative #0");
            Assert.NotNull(newCreatives[1]);
            Assert.That(newCreatives[1] is ImageCreative);
            Assert.AreEqual(newCreatives[1].advertiserId, advertiserId);
            Assert.AreEqual(newCreatives[1].name, "Image creative #1");
        }
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="service">An initialized Dfa Reporting service object
    /// </param>
    public override void Run(DfareportingService service) {
      long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE"));
      long sizeId = long.Parse(_T("INSERT_SIZE_ID_HERE"));
      long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE"));

      string pathToHtml5AssetFile = _T("INSERT_PATH_TO_HTML5_ASSET_FILE_HERE");
      string pathToImageAssetFile = _T("INSERT_PATH_TO_IMAGE_ASSET_FILE_HERE");

      Creative creative = new Creative();
      creative.AdvertiserId = advertiserId;
      creative.Name = "Test HTML5 banner creative";
      creative.Size = new Size() { Id = sizeId };
      creative.Type = "HTML5_BANNER";

      // Upload the HTML5 asset.
      CreativeAssetUtils assetUtils = new CreativeAssetUtils(service, profileId, advertiserId);
      CreativeAssetId html5AssetId = assetUtils.uploadAsset(pathToHtml5AssetFile, "HTML");

      CreativeAsset html5Asset = new CreativeAsset();
      html5Asset.AssetIdentifier = html5AssetId;
      html5Asset.Role = "PRIMARY";

      // Upload the backup image asset.
      CreativeAssetId imageAssetId = assetUtils.uploadAsset(pathToImageAssetFile, "HTML_IMAGE");

      CreativeAsset imageAsset = new CreativeAsset();
      imageAsset.AssetIdentifier = imageAssetId;
      imageAsset.Role = "BACKUP_IMAGE";

      // Add the creative assets.
      creative.CreativeAssets = new List<CreativeAsset>() { html5Asset, imageAsset };

      // Add a click tag.
      ClickTag clickTag = new ClickTag() { Name = "clickTag" };
      creative.ClickTags = new List<ClickTag>() { clickTag };

      Creative result = service.Creatives.Insert(creative, profileId).Execute();

      // Display the new creative ID.
      Console.WriteLine("HTML5 banner creative with ID {0} was created.", result.Id);
    }
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="service">An initialized Dfa Reporting service object
    /// </param>
    public override void Run(DfareportingService service) {
      long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE"));
      long sizeId = long.Parse(_T("INSERT_SIZE_ID_HERE"));
      long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE"));

      string pathToFlashAssetFile = _T("INSERT_PATH_TO_FLASH_ASSET_FILE_HERE");
      string pathToImageAssetFile = _T("INSERT_PATH_TO_IMAGE_ASSET_FILE_HERE");

      Creative creative = new Creative();
      creative.AdvertiserId = advertiserId;
      creative.Name = "Test flash in-page creative";
      creative.Size = new Size() { Id = sizeId };
      creative.Type = "FLASH_INPAGE";

      // Upload the flash asset.
      CreativeAssetUtils assetUtils = new CreativeAssetUtils(service, profileId, advertiserId);
      CreativeAssetId flashAssetId = assetUtils.uploadAsset(pathToFlashAssetFile, "FLASH");

      CreativeAsset flashAsset = new CreativeAsset();
      flashAsset.AssetIdentifier = flashAssetId;
      flashAsset.Role = "PRIMARY";
      flashAsset.WindowMode = "TRANSPARENT";

      // Upload the backup image asset.
      CreativeAssetId imageAssetId = assetUtils.uploadAsset(pathToImageAssetFile, "HTML_IMAGE");

      CreativeAsset imageAsset = new CreativeAsset();
      imageAsset.AssetIdentifier = imageAssetId;
      imageAsset.Role = "BACKUP_IMAGE";

      // Add the creative assets.
      creative.CreativeAssets = new List<CreativeAsset>() { flashAsset, imageAsset };

      // Set the backup image target window option.
      creative.BackupImageTargetWindow = new TargetWindow() { TargetWindowOption = "NEW_WINDOW"};

      Creative result = service.Creatives.Insert(creative, profileId).Execute();

      // Display the new creative ID.
      Console.WriteLine("Flash in-page creative with ID {0} was created.", result.Id);
    }
Exemple #17
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="service">An initialized Dfa Reporting service object
        /// </param>
        public override void Run(DfareportingService service)
        {
            long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE"));
            long sizeId       = long.Parse(_T("INSERT_SIZE_ID_HERE"));
            long profileId    = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE"));

            string pathToImageAssetFile = _T("INSERT_PATH_TO_IMAGE_ASSET_FILE_HERE");

            Creative creative = new Creative();

            creative.AdvertiserId = advertiserId;
            creative.Name         = "Test image display creative";
            creative.Size         = new Size()
            {
                Id = sizeId
            };
            creative.Type = "DISPLAY";

            // Upload the image asset.
            CreativeAssetUtils assetUtils   = new CreativeAssetUtils(service, profileId, advertiserId);
            CreativeAssetId    imageAssetId =
                assetUtils.uploadAsset(pathToImageAssetFile, "HTML_IMAGE").AssetIdentifier;

            CreativeAsset imageAsset = new CreativeAsset();

            imageAsset.AssetIdentifier = imageAssetId;
            imageAsset.Role            = "PRIMARY";

            // Add the creative assets.
            creative.CreativeAssets = new List <CreativeAsset>()
            {
                imageAsset
            };

            Creative result = service.Creatives.Insert(creative, profileId).Execute();

            // Display the new creative ID.
            Console.WriteLine("Image display creative with ID {0} was created.", result.Id);
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The Dfa user object running the code example.
        /// </param>
        public override void Run(DfaUser user)
        {
            // Request the creative service from the service client factory.
            CreativeRemoteService creativeService = (CreativeRemoteService)user.GetService(
                DfaService.v1_20.CreativeRemoteService);

            string assetName      = _T("INSERT_ASSET_NAME_HERE");
            string pathToFile     = _T("INSERT_PATH_TO_FILE_HERE");
            long   creativeId     = long.Parse(_T("INSERT_IN_STREAM_VIDEO_CREATIVE_ID_HERE"));
            string assetToReplace = _T("INSERT_ASSET_TO_REPLACE_HERE");

            // Create the In-Stream creative asset.
            CreativeAsset inStreamVideoAsset = new CreativeAsset();

            inStreamVideoAsset.name    = assetName;
            inStreamVideoAsset.content = MediaUtilities.GetAssetDataFromUrl(
                new Uri(pathToFile).AbsoluteUri);

            // Create an upload request to make this asset a companion ad file for an
            // existing In-Stream video creative.
            InStreamAssetUploadRequest inStreamAssetUploadRequest = new InStreamAssetUploadRequest();

            inStreamAssetUploadRequest.companion     = true;
            inStreamAssetUploadRequest.inStreamAsset = inStreamVideoAsset;
            inStreamAssetUploadRequest.creativeId    = creativeId;

            try {
                // Replace the existing asset with a newly uploaded asset.
                InStreamVideoCreative inStreamVideoCreative =
                    creativeService.replaceInStreamAsset(assetToReplace, inStreamAssetUploadRequest);

                // Display a success message.
                Console.WriteLine("Replaced companion ad asset \"{0}\" in In-Stream video creative "
                                  + "with ID \"{1}\".%n", assetToReplace, inStreamVideoCreative.id);
            } catch (Exception ex) {
                Console.WriteLine("Failed to replace companion ad asset in in-stream video creative. " +
                                  "Exception says \"{0}\"", ex.Message);
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The Dfa user object running the code example.
        /// </param>
        public override void Run(DfaUser user)
        {
            // Request the creative service from the service client factory.
            CreativeRemoteService creativeService = (CreativeRemoteService)user.GetService(
                DfaService.v1_19.CreativeRemoteService);

            string assetName  = _T("INSERT_ASSET_NAME_HERE");
            string pathToFile = _T("INSERT_PATH_TO_FILE_HERE");
            long   creativeId = long.Parse(_T("INSERT_IN_STREAM_VIDEO_CREATIVE_ID_HERE"));

            // Create the In-Stream video creative asset.
            CreativeAsset inStreamVideoAsset = new CreativeAsset();

            inStreamVideoAsset.name    = assetName;
            inStreamVideoAsset.content = MediaUtilities.GetAssetDataFromUrl(
                new Uri(pathToFile).AbsolutePath);

            // Create an upload request to make this asset a media file for an existing
            // In-Stream creative.
            InStreamAssetUploadRequest inStreamAssetUploadRequest = new InStreamAssetUploadRequest();

            inStreamAssetUploadRequest.mediaFile     = true;
            inStreamAssetUploadRequest.inStreamAsset = inStreamVideoAsset;
            inStreamAssetUploadRequest.creativeId    = creativeId;

            try {
                // Save the media file.
                InStreamVideoCreative inStreamVideoCreative =
                    creativeService.uploadInStreamAsset(inStreamAssetUploadRequest);

                // Display a success message.
                Console.WriteLine("Added a media file to In-Stream video creative with ID \"{0}\".",
                                  inStreamVideoCreative.id);
            } catch (Exception ex) {
                Console.WriteLine("Failed to add a media file to in-stream video creative. " +
                                  "Exception says \"{0}\"", ex.Message);
            }
        }
Exemple #20
0
        public void TestCreateCreative()
        {
            // Create creative size.
            Size size = new Size();

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

            // Create an image creative.
            ImageCreative imageCreative = new ImageCreative();

            imageCreative.name           = string.Format("Image creative #{0}", new TestUtils().GetTimeStamp());
            imageCreative.advertiserId   = advertiserId;
            imageCreative.destinationUrl = "http://www.google.com";
            imageCreative.size           = size;

            // Create image asset.
            CreativeAsset creativeAsset = new CreativeAsset();

            creativeAsset.fileName       = "image.jpg";
            creativeAsset.assetByteArray = MediaUtilities.GetAssetDataFromUrl(
                "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg");
            creativeAsset.size = size;
            imageCreative.primaryImageAsset = creativeAsset;

            Creative newCreative = null;

            Assert.DoesNotThrow(delegate() {
                newCreative = creativeService.createCreative(imageCreative);
            });

            Assert.NotNull(newCreative);
            Assert.That(newCreative is ImageCreative);
            Assert.AreEqual(newCreative.advertiserId, imageCreative.advertiserId);
            Assert.AreEqual(newCreative.name, imageCreative.name);
        }
Exemple #21
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="service">An initialized Dfa Reporting service object
        /// </param>
        public override void Run(DfareportingService service)
        {
            long instreamVideoCreativeId = long.Parse(_T("INSERT_INSTREAM_VIDEO_CREATIVE_ID_HERE"));
            long targetingTemplateId     = long.Parse(_T("INSERT_TARGETING_TEMPLATE_ID_HERE"));
            long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE"));

            string videoAssetName       = _T("INSERT_VIDEO_ASSET_NAME_HERE");
            string pathToVideoAssetFile = _T("INSERT_PATH_TO_VIDEO_ASSET_FILE_HERE");

            // Retrieve the specified creative.
            Creative creative = service.Creatives.Get(profileId, instreamVideoCreativeId).Execute();

            if (creative == null || !"INSTREAM_VIDEO".Equals(creative.Type))
            {
                Console.Error.WriteLine("Invalid creative specified.");
                return;
            }

            CreativeAssetSelection selection = creative.CreativeAssetSelection;

            if (!creative.DynamicAssetSelection.Value)
            {
                // Locate an existing video asset to use as a default.
                // This example uses the first PARENT_VIDEO asset found.
                CreativeAsset defaultAsset =
                    creative.CreativeAssets.First(asset => "PARENT_VIDEO".Equals(asset.Role));
                if (defaultAsset == null)
                {
                    Console.Error.WriteLine("Default video asset could not be found.");
                    return;
                }

                // Create a new selection using the existing asset as a default.
                selection = new CreativeAssetSelection();
                selection.DefaultAssetId = defaultAsset.Id;
                selection.Rules          = new List <Rule>();

                // Enable dynamic asset selection for the creative.
                creative.DynamicAssetSelection  = true;
                creative.CreativeAssetSelection = selection;
            }

            // Upload the new video asset and add it to the creative.
            CreativeAssetUtils assetUtils = new CreativeAssetUtils(service, profileId,
                                                                   creative.AdvertiserId.Value);
            CreativeAssetMetadata videoMetadata = assetUtils.uploadAsset(pathToVideoAssetFile, "VIDEO");

            creative.CreativeAssets.Add(new CreativeAsset()
            {
                AssetIdentifier = videoMetadata.AssetIdentifier,
                Role            = "PARENT_VIDEO"
            });

            // Create a rule targeting the new video asset and add it to the selection.
            Rule rule = new Rule();

            rule.AssetId             = videoMetadata.Id;
            rule.Name                = "Test rule for asset " + videoMetadata.Id;
            rule.TargetingTemplateId = targetingTemplateId;
            selection.Rules.Add(rule);

            // Update the creative.
            Creative result = service.Creatives.Update(creative, profileId).Execute();

            Console.WriteLine("Dynamic asset selection enabled for creative with ID {0}.", result.Id);
        }
    /// <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 CreativeService.
      CreativeService creativeService =
          (CreativeService) user.GetService(DfpService.v201511.CreativeService);

      // Set the ID of the advertiser (company) that all creative will be
      // assigned to.
      long advertiserId = long.Parse(_T("INSERT_ADVERTISER_COMPANY_ID_HERE"));

      // Use the image banner with optional third party tracking template.
      long creativeTemplateId = 10000680L;

      // Create the local custom creative object.
      TemplateCreative templateCreative = new TemplateCreative();
      templateCreative.name = "Template creative";
      templateCreative.advertiserId = advertiserId;
      templateCreative.creativeTemplateId = creativeTemplateId;

      // Set the creative size.
      Size size = new Size();
      size.width = 300;
      size.height = 250;
      size.isAspectRatio = false;

      templateCreative.size = size;

      // Create the asset variable value.
      AssetCreativeTemplateVariableValue assetVariableValue =
          new AssetCreativeTemplateVariableValue();
      assetVariableValue.uniqueName = "Imagefile";
      CreativeAsset asset = new CreativeAsset();
      asset.assetByteArray = MediaUtilities.GetAssetDataFromUrl(
          "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg");
      asset.fileName = String.Format("image{0}.jpg", this.GetTimeStamp());
      assetVariableValue.asset = asset;

      // Create the image width variable value.
      LongCreativeTemplateVariableValue imageWidthVariableValue =
          new LongCreativeTemplateVariableValue();
      imageWidthVariableValue.uniqueName = "Imagewidth";
      imageWidthVariableValue.value = 300;

      // Create the image height variable value.
      LongCreativeTemplateVariableValue imageHeightVariableValue =
          new LongCreativeTemplateVariableValue();
      imageHeightVariableValue.uniqueName = "Imageheight";
      imageHeightVariableValue.value = 250;

      // Create the URL variable value.
      UrlCreativeTemplateVariableValue urlVariableValue = new UrlCreativeTemplateVariableValue();
      urlVariableValue.uniqueName = "ClickthroughURL";
      urlVariableValue.value = "www.google.com";

      // Create the target window variable value.
      StringCreativeTemplateVariableValue targetWindowVariableValue =
          new StringCreativeTemplateVariableValue();
      targetWindowVariableValue.uniqueName = "Targetwindow";
      targetWindowVariableValue.value = "_blank";

      templateCreative.creativeTemplateVariableValues = new BaseCreativeTemplateVariableValue[] {
          assetVariableValue, imageWidthVariableValue, imageHeightVariableValue, urlVariableValue,
          targetWindowVariableValue};

      try {
        // Create the template creative on the server.
        Creative[] createdTemplateCreatives = creativeService.createCreatives(
            new Creative[] {templateCreative});

        foreach (Creative createdTemplateCreative in createdTemplateCreatives) {
          Console.WriteLine("A template creative with ID \"{0}\", name \"{1}\", and type " +
              "\"{2}\" was created and can be previewed at {3}", createdTemplateCreative.id,
              createdTemplateCreative.name, createdTemplateCreative.GetType().Name,
              createdTemplateCreative.previewUrl);
        }
      } catch (Exception e) {
        Console.WriteLine("Failed to create creatives. 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 CreativeService.
      CreativeService creativeService =
          (CreativeService) user.GetService(DfpService.v201511.CreativeService);

      // Set the ID of the advertiser (company) that all creatives will be
      // assigned to.
      long advertiserId = long.Parse(_T("INSERT_ADVERTISER_COMPANY_ID_HERE"));

      // Create an array to store local image creative objects.
      Creative[] imageCreatives = new ImageCreative[5];

      for (int i = 0; i < 5; i++) {
        // Create creative size.
        Size size = new Size();
        size.width = 300;
        size.height = 250;

        // Create an image creative.
        ImageCreative imageCreative = new ImageCreative();
        imageCreative.name = string.Format("Image creative #{0}", i);
        imageCreative.advertiserId = advertiserId;
        imageCreative.destinationUrl = "http://www.google.com";
        imageCreative.size = size;

        // Create image asset.
        CreativeAsset creativeAsset = new CreativeAsset();
        creativeAsset.fileName = "image.jpg";
        creativeAsset.assetByteArray = MediaUtilities.GetAssetDataFromUrl(
            "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg");
        creativeAsset.size = size;
        imageCreative.primaryImageAsset = creativeAsset;

        imageCreatives[i] = imageCreative;
      }

      try {
        // Create the image creatives on the server.
        imageCreatives = creativeService.createCreatives(imageCreatives);

        if (imageCreatives != null) {
          foreach (Creative creative in imageCreatives) {
            // Use "is" operator to determine what type of creative was
            // returned.
            if (creative is ImageCreative) {
              ImageCreative imageCreative = (ImageCreative) creative;
              Console.WriteLine("An image creative with ID ='{0}', name ='{1}' and size = " +
                  "({2},{3}) was created and can be previewed at: {4}", imageCreative.id,
                  imageCreative.name, imageCreative.size.width, imageCreative.size.height,
                  imageCreative.previewUrl);
            } else {
              Console.WriteLine("A creative with ID ='{0}', name='{1}' and type='{2}' was created.",
                  creative.id, creative.name, creative.GetType().Name);
            }
          }
        } else {
          Console.WriteLine("No creatives created.");
        }
      } catch (Exception e) {
        Console.WriteLine("Failed to create creatives. Exception says \"{0}\"", e.Message);
      }
    }
    public void TestCreateCreatives() {
      // Create an array to store local image creative objects.
      Creative[] imageCreatives = new ImageCreative[2];

      for (int i = 0; i < 2; i++) {
        // Create creative size.
        Size size = new Size();
        size.width = 300;
        size.height = 250;

        // Create an image creative.
        ImageCreative imageCreative = new ImageCreative();
        imageCreative.name = string.Format("Image creative #{0}", i);
        imageCreative.advertiserId = advertiserId;
        imageCreative.destinationUrl = "http://www.google.com";
        imageCreative.size = size;

        // Create image asset.
        CreativeAsset creativeAsset = new CreativeAsset();
        creativeAsset.fileName = "image.jpg";
        creativeAsset.assetByteArray = MediaUtilities.GetAssetDataFromUrl(
            "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg");
        creativeAsset.size = size;
        imageCreative.primaryImageAsset = creativeAsset;

        imageCreatives[i] = imageCreative;
      }

      Creative[] newCreatives = null;

      Assert.DoesNotThrow(delegate() {
        newCreatives = creativeService.createCreatives(imageCreatives);
      });

      Assert.NotNull(newCreatives);
      Assert.AreEqual(newCreatives.Length, 2);
      Assert.NotNull(newCreatives[0]);
      Assert.That(newCreatives[0] is ImageCreative);
      Assert.AreEqual(newCreatives[0].advertiserId, advertiserId);
      Assert.AreEqual(newCreatives[0].name, "Image creative #0");
      Assert.NotNull(newCreatives[1]);
      Assert.That(newCreatives[1] is ImageCreative);
      Assert.AreEqual(newCreatives[1].advertiserId, advertiserId);
      Assert.AreEqual(newCreatives[1].name, "Image creative #1");
    }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="service">An initialized Dfa Reporting service object
        /// </param>
        public override void Run(DfareportingService service)
        {
            long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE"));
            long sizeId       = long.Parse(_T("INSERT_SIZE_ID_HERE"));
            long profileId    = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE"));

            string pathToImageAssetFile  = _T("INSERT_PATH_TO_IMAGE_ASSET_FILE_HERE");
            string pathToImageAsset2File = _T("INSERT_PATH_TO_IMAGE_ASSET_FILE_HERE");

            Creative creative = new Creative();

            creative.AdvertiserId      = advertiserId;
            creative.AutoAdvanceImages = true;
            creative.Name = "Test display image gallery creative";
            creative.Size = new Size()
            {
                Id = sizeId
            };
            creative.Type = "DISPLAY_IMAGE_GALLERY";

            // Upload the first image asset.
            CreativeAssetUtils assetUtils    = new CreativeAssetUtils(service, profileId, advertiserId);
            CreativeAssetId    imageAsset1Id =
                assetUtils.uploadAsset(pathToImageAssetFile, "HTML_IMAGE").AssetIdentifier;

            CreativeAsset imageAsset1 = new CreativeAsset();

            imageAsset1.AssetIdentifier = imageAsset1Id;
            imageAsset1.Role            = "PRIMARY";

            // Upload the second image asset.
            CreativeAssetId imageAsset2Id =
                assetUtils.uploadAsset(pathToImageAsset2File, "HTML_IMAGE").AssetIdentifier;

            CreativeAsset imageAsset2 = new CreativeAsset();

            imageAsset2.AssetIdentifier = imageAsset2Id;
            imageAsset2.Role            = "PRIMARY";

            // Add the creative assets.
            creative.CreativeAssets = new List <CreativeAsset>()
            {
                imageAsset1, imageAsset2
            };

            // Create a click tag for the first image asset.
            ClickTag clickTag1 = new ClickTag();

            clickTag1.Name      = imageAsset1Id.Name;
            clickTag1.EventName = imageAsset1Id.Name;

            // Create a click tag for the second image asset.
            ClickTag clickTag2 = new ClickTag();

            clickTag2.Name      = imageAsset2Id.Name;
            clickTag2.EventName = imageAsset2Id.Name;

            // Add the click tags.
            creative.ClickTags = new List <ClickTag>()
            {
                clickTag1, clickTag2
            };

            Creative result = service.Creatives.Insert(creative, profileId).Execute();

            // Display the new creative ID.
            Console.WriteLine("Display image gallery creative with ID {0} was created.", result.Id);
        }
Exemple #26
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(AdManagerUser user)
        {
            using (CreativeService creativeService = user.GetService <CreativeService>())
            {
                // Set the ID of the advertiser (company) that all creatives will be
                // assigned to.
                long advertiserId = long.Parse(_T("INSERT_ADVERTISER_COMPANY_ID_HERE"));

                // Create an array to store local image creative objects.
                Creative[] imageCreatives = new ImageCreative[5];

                for (int i = 0; i < 5; i++)
                {
                    // Create creative size.
                    Size size = new Size();
                    size.width  = 300;
                    size.height = 250;

                    // Create an image creative.
                    ImageCreative imageCreative = new ImageCreative();
                    imageCreative.name           = string.Format("Image creative #{0}", i);
                    imageCreative.advertiserId   = advertiserId;
                    imageCreative.destinationUrl = "http://www.google.com";
                    imageCreative.size           = size;

                    // Create image asset.
                    CreativeAsset creativeAsset = new CreativeAsset();
                    creativeAsset.fileName       = "image.jpg";
                    creativeAsset.assetByteArray =
                        MediaUtilities.GetAssetDataFromUrl("https://goo.gl/3b9Wfh", user.Config);
                    creativeAsset.size = size;
                    imageCreative.primaryImageAsset = creativeAsset;

                    imageCreatives[i] = imageCreative;
                }

                try
                {
                    // Create the image creatives on the server.
                    imageCreatives = creativeService.createCreatives(imageCreatives);

                    if (imageCreatives != null)
                    {
                        foreach (Creative creative in imageCreatives)
                        {
                            // Use "is" operator to determine what type of creative was
                            // returned.
                            if (creative is ImageCreative)
                            {
                                ImageCreative imageCreative = (ImageCreative)creative;
                                Console.WriteLine(
                                    "An image creative with ID ='{0}', name ='{1}' and size = " +
                                    "({2},{3}) was created and can be previewed at: {4}",
                                    imageCreative.id, imageCreative.name, imageCreative.size.width,
                                    imageCreative.size.height, imageCreative.previewUrl);
                            }
                            else
                            {
                                Console.WriteLine(
                                    "A creative with ID ='{0}', name='{1}' and type='{2}' " +
                                    "was created.", creative.id, creative.name,
                                    creative.GetType().Name);
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("No creatives created.");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to create creatives. Exception says \"{0}\"",
                                      e.Message);
                }
            }
        }
Exemple #27
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            using (CreativeService creativeService =
                       (CreativeService)user.GetService(DfpService.v201805.CreativeService)) {
                // Set the ID of the advertiser (company) that all creative will be
                // assigned to.
                long advertiserId = long.Parse(_T("INSERT_ADVERTISER_COMPANY_ID_HERE"));

                // Use the image banner with optional third party tracking template.
                long creativeTemplateId = 10000680L;

                // Create the local custom creative object.
                TemplateCreative templateCreative = new TemplateCreative();
                templateCreative.name               = "Template creative";
                templateCreative.advertiserId       = advertiserId;
                templateCreative.creativeTemplateId = creativeTemplateId;

                // Set the creative size.
                Size size = new Size();
                size.width         = 300;
                size.height        = 250;
                size.isAspectRatio = false;

                templateCreative.size = size;

                // Create the asset variable value.
                AssetCreativeTemplateVariableValue assetVariableValue =
                    new AssetCreativeTemplateVariableValue();
                assetVariableValue.uniqueName = "Imagefile";
                CreativeAsset asset = new CreativeAsset();
                asset.assetByteArray = MediaUtilities.GetAssetDataFromUrl("https://goo.gl/3b9Wfh",
                                                                          user.Config);
                asset.fileName           = String.Format("image{0}.jpg", this.GetTimeStamp());
                assetVariableValue.asset = asset;

                // Create the image width variable value.
                LongCreativeTemplateVariableValue imageWidthVariableValue =
                    new LongCreativeTemplateVariableValue();
                imageWidthVariableValue.uniqueName = "Imagewidth";
                imageWidthVariableValue.value      = 300;

                // Create the image height variable value.
                LongCreativeTemplateVariableValue imageHeightVariableValue =
                    new LongCreativeTemplateVariableValue();
                imageHeightVariableValue.uniqueName = "Imageheight";
                imageHeightVariableValue.value      = 250;

                // Create the URL variable value.
                UrlCreativeTemplateVariableValue urlVariableValue = new UrlCreativeTemplateVariableValue();
                urlVariableValue.uniqueName = "ClickthroughURL";
                urlVariableValue.value      = "www.google.com";

                // Create the target window variable value.
                StringCreativeTemplateVariableValue targetWindowVariableValue =
                    new StringCreativeTemplateVariableValue();
                targetWindowVariableValue.uniqueName = "Targetwindow";
                targetWindowVariableValue.value      = "_blank";

                templateCreative.creativeTemplateVariableValues = new BaseCreativeTemplateVariableValue[] {
                    assetVariableValue, imageWidthVariableValue, imageHeightVariableValue, urlVariableValue,
                    targetWindowVariableValue
                };

                try {
                    // Create the template creative on the server.
                    Creative[] createdTemplateCreatives = creativeService.createCreatives(
                        new Creative[] { templateCreative });

                    foreach (Creative createdTemplateCreative in createdTemplateCreatives)
                    {
                        Console.WriteLine("A template creative with ID \"{0}\", name \"{1}\", and type " +
                                          "\"{2}\" was created and can be previewed at {3}", createdTemplateCreative.id,
                                          createdTemplateCreative.name, createdTemplateCreative.GetType().Name,
                                          createdTemplateCreative.previewUrl);
                    }
                } catch (Exception e) {
                    Console.WriteLine("Failed to create creatives. 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 CreativeService.
            CreativeService creativeService =
                (CreativeService)user.GetService(DfpService.v201311.CreativeService);

            long[] creativeIds = new long[] { long.Parse(_T("INSERT_IMAGE_CREATIVE_ID_HERE")) };

            // Build a comma separated list of creativeIds. Note that if you are using
            // .NET 4.0 or above, you could use the newly introduced
            // String.Join<T>(string separator, IEnumerable<T> values) method to
            // perform this task.
            string[] creativeIdTexts = new string[creativeIds.Length];
            for (int i = 0; i < creativeIdTexts.Length; i++)
            {
                creativeIdTexts[i] = creativeIds[i].ToString();
            }

            string commaSeparatedCreativeIds = string.Join(",", creativeIdTexts);

            // Create the statement to filter image creatives by id.
            Statement statement = new StatementBuilder(
                string.Format("WHERE id IN ({0}) and creativeType = :creativeType LIMIT 500",
                              commaSeparatedCreativeIds)).AddValue("creativeType", "ImageCreative").
                                  ToStatement();

            try {
                // Retrieve all creatives which match.
                CreativePage page = creativeService.getCreativesByStatement(statement);

                if (page.results != null)
                {
                    Creative[] creatives = page.results;
                    long[]     oldIds    = new long[creatives.Length];
                    for (int i = 0; i < creatives.Length; i++)
                    {
                        ImageCreative imageCreative = (ImageCreative)creatives[i];
                        oldIds[i] = imageCreative.id;
                        // Since we cannot set id to null, we mark it as not specified.
                        imageCreative.idSpecified = false;

                        imageCreative.advertiserId = imageCreative.advertiserId;
                        imageCreative.name         = imageCreative.name + " (Copy #" + GetTimeStamp() + ")";

                        // Create image asset.
                        CreativeAsset creativeAsset = new CreativeAsset();
                        creativeAsset.fileName       = "image.jpg";
                        creativeAsset.assetByteArray = MediaUtilities.GetAssetDataFromUrl(
                            imageCreative.primaryImageAsset.assetUrl);

                        creativeAsset.size = imageCreative.primaryImageAsset.size;
                        imageCreative.primaryImageAsset = creativeAsset;

                        creatives[i] = imageCreative;
                    }

                    // Create the copied creative.
                    creatives = creativeService.createCreatives(creatives);

                    // Display copied creatives.
                    for (int i = 0; i < creatives.Length; i++)
                    {
                        Console.WriteLine("Image creative with ID \"{0}\" copied to ID \"{1}\".", oldIds[i],
                                          creatives[i].id);
                    }
                }
                else
                {
                    Console.WriteLine("No creatives were copied.");
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to copy creatives. Exception says \"{0}\"", ex.Message);
            }
        }
Exemple #29
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="service">An initialized Dfa Reporting service object
        /// </param>
        public override void Run(DfareportingService service)
        {
            long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE"));
            long sizeId       = long.Parse(_T("INSERT_SIZE_ID_HERE"));
            long profileId    = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE"));

            string pathToHtml5AssetFile = _T("INSERT_PATH_TO_HTML5_ASSET_FILE_HERE");
            string pathToImageAssetFile = _T("INSERT_PATH_TO_IMAGE_ASSET_FILE_HERE");

            Creative creative = new Creative();

            creative.AdvertiserId = advertiserId;
            creative.Name         = "Test HTML5 display creative";
            creative.Size         = new Size()
            {
                Id = sizeId
            };
            creative.Type = "DISPLAY";

            // Upload the HTML5 asset.
            CreativeAssetUtils assetUtils   = new CreativeAssetUtils(service, profileId, advertiserId);
            CreativeAssetId    html5AssetId =
                assetUtils.uploadAsset(pathToHtml5AssetFile, "HTML").AssetIdentifier;

            CreativeAsset html5Asset = new CreativeAsset();

            html5Asset.AssetIdentifier = html5AssetId;
            html5Asset.Role            = "PRIMARY";

            // Upload the backup image asset.
            CreativeAssetId imageAssetId =
                assetUtils.uploadAsset(pathToImageAssetFile, "HTML_IMAGE").AssetIdentifier;

            CreativeAsset imageAsset = new CreativeAsset();

            imageAsset.AssetIdentifier = imageAssetId;
            imageAsset.Role            = "BACKUP_IMAGE";

            // Add the creative assets.
            creative.CreativeAssets = new List <CreativeAsset>()
            {
                html5Asset, imageAsset
            };

            // Configure the bacup image.
            creative.BackupImageClickThroughUrl = "https://www.google.com";
            creative.BackupImageReportingLabel  = "backup";
            creative.BackupImageTargetWindow    = new TargetWindow()
            {
                TargetWindowOption = "NEW_WINDOW"
            };

            // Add a click tag.
            ClickTag clickTag = new ClickTag();

            clickTag.Name      = "clickTag";
            clickTag.EventName = "exit";
            clickTag.Value     = "https://www.google.com";
            creative.ClickTags = new List <ClickTag>()
            {
                clickTag
            };

            Creative result = service.Creatives.Insert(creative, profileId).Execute();

            // Display the new creative ID.
            Console.WriteLine("HTML5 display creative with ID {0} was created.", result.Id);
        }
        /// <summary>
        /// Create a test company for running further tests.
        /// </summary>
        /// <returns>A creative for running further tests.</returns>
        public Creative CreateCreative(DfpUser user, long advertiserId)
        {
            CreativeService creativeService = (CreativeService)user.GetService(
              DfpService.v201511.CreativeService);

              // Create creative size.
              Size size = new Size();
              size.width = 300;
              size.height = 250;

              // Create an image creative.
              ImageCreative imageCreative = new ImageCreative();
              imageCreative.name = string.Format("Image creative #{0}", GetTimeStamp());
              imageCreative.advertiserId = advertiserId;
              imageCreative.destinationUrl = "http://www.google.com";
              imageCreative.size = size;

              // Create image asset.
              CreativeAsset creativeAsset = new CreativeAsset();
              creativeAsset.fileName = "image.jpg";
              creativeAsset.assetByteArray = MediaUtilities.GetAssetDataFromUrl(
              "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg");
              creativeAsset.size = size;
              imageCreative.primaryImageAsset = creativeAsset;

              return creativeService.createCreatives(new Creative[] {imageCreative})[0];
        }