/// <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.v201508.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";
      assetVariableValue.assetByteArray = MediaUtilities.GetAssetDataFromUrl(
          "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg");
      assetVariableValue.fileName = String.Format("image{0}.jpg", this.GetTimeStamp());

      // 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);
      }
    }
Exemplo n.º 2
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);

            // 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";
            assetVariableValue.assetByteArray = MediaUtilities.GetAssetDataFromUrl(
                "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg");
            assetVariableValue.fileName = String.Format("image{0}.jpg", this.GetTimeStamp());

            // 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.
                templateCreative = (TemplateCreative)creativeService.createCreative(templateCreative);

                if (templateCreative != null)
                {
                    Console.WriteLine("A template creative with ID \"{0}\", name \"{1}\", and type \"{2}\" " +
                                      "was created and can be previewed at {3}", templateCreative.id, templateCreative.name,
                                      templateCreative.CreativeType, templateCreative.previewUrl);
                }
                else
                {
                    Console.WriteLine("No creatives were created.");
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to create creatives. Exception says \"{0}\"", ex.Message);
            }
        }