/// <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.v201306.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.createCreative(imageCreative));
        }
Beispiel #2
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 CreativeService.
            CreativeService creativeService =
                (CreativeService)user.GetService(DfpService.v201311.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";
            customCreativeAsset.fileName       = string.Format("inline{0}.jpg", GetTimeStamp());
            customCreativeAsset.assetByteArray = MediaUtilities.GetAssetDataFromUrl(
                "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg");
            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.
                customCreative = (CustomCreative)creativeService.createCreative(customCreative);

                if (customCreative != null)
                {
                    Console.WriteLine("A custom creative with ID \"{0}\", name \"{1}\", and size ({2}, " +
                                      "{3}) was created and can be previewed at {4}", customCreative.id,
                                      customCreative.name, customCreative.size.width, customCreative.size.height,
                                      customCreative.previewUrl);
                }
                else
                {
                    Console.WriteLine("No creative created.");
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to create custom creatives. Exception says \"{0}\"", ex.Message);
            }
        }
Beispiel #3
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);
        }
        /// <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);
            }
        }