/// <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 creative to get.
            long creativeId = long.Parse(_T("INSERT_CREATIVE_ID_HERE"));

            try {
                // Get the creative.
                Creative creative = creativeService.getCreative(creativeId);

                if (creative != null)
                {
                    Console.WriteLine("Creative with ID ='{0}', name ='{1}' and type ='{2}' " +
                                      "was found.", creative.id, creative.name, creative.CreativeType);
                }
                else
                {
                    Console.WriteLine("No creative found for this ID.");
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to get creative. Exception says \"{0}\"", ex.Message);
            }
        }
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);

            // Create a Statement to only select image creatives.
            Statement statement = new StatementBuilder("WHERE creativeType = :creativeType LIMIT 500").
                                  AddValue("creativeType", "ImageCreative").ToStatement();

            try {
                // Get creatives by Statement.
                CreativePage page = creativeService.getCreativesByStatement(statement);

                if (page.results != null && page.results.Length > 0)
                {
                    int i = page.startIndex;
                    foreach (Creative creative in page.results)
                    {
                        Console.WriteLine("{0}) Creative with ID ='{1}', name ='{2}' and type ='{3}' " +
                                          "was found.", i, creative.id, creative.name, creative.CreativeType);
                        i++;
                    }
                }

                Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
            } catch (Exception ex) {
                Console.WriteLine("Failed to get creatives by Statement. Exception says \"{0}\"",
                                  ex.Message);
            }
        }
Beispiel #3
0
 public CreativeController(ApplicationDbContext DataBaseConnection)
 {
     this.dataBaseConnection = DataBaseConnection;
     CreativeService         = new CreativeService(dataBaseConnection);
     ChapterService          = new ChapterService(dataBaseConnection);
     CloudinaryService       = new CloudinaryService(dataBaseConnection);
 }
 public void Init() {
   TestUtils utils = new TestUtils();
   creativeService = (CreativeService)user.GetService(DfpService.v201508.CreativeService);
   advertiserId = utils.CreateCompany(user, CompanyType.ADVERTISER).id;
   creative1 = utils.CreateCreative(user, advertiserId);
   creative2 = utils.CreateCreative(user, advertiserId);
 }
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            // Get the CreativeService.
            CreativeService creativeService =
                (CreativeService)user.GetService(DfpService.v201705.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>
        /// 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.v201602.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]);
        }
Beispiel #7
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 a video creative.
                VideoCreative videoCreative = new VideoCreative()
                {
                    name           = string.Format("Video creative #{0}", new Random().Next(int.MaxValue)),
                    advertiserId   = advertiserId,
                    destinationUrl = "https://www.google.com",
                    videoSourceUrl =
                        "https://storage.googleapis.com/interactive-media-ads/media/android.mp4",
                    duration = 115000,
                    size     = new Size()
                    {
                        width  = 640,
                        height = 360
                    }
                };

                try
                {
                    // Create the video creative on the server.
                    Creative[] videoCreatives =
                        creativeService.createCreatives(new VideoCreative[] { videoCreative });

                    if (videoCreatives != null)
                    {
                        foreach (Creative creative in videoCreatives)
                        {
                            // Use "is" operator to determine what type of creative was
                            // returned.
                            if (creative is VideoCreative)
                            {
                                Console.WriteLine(
                                    "A video creative with ID ='{0}' and name ='{1}' " +
                                    "was created and can be previewed at: {2}",
                                    creative.id,
                                    creative.name,
                                    ((VideoCreative)creative).vastPreviewUrl);
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("No creatives created.");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to create creatives. Exception says \"{0}\"",
                                      e.Message);
                }
            }
        }
        public void Init()
        {
            TestUtils utils = new TestUtils();

            creativeService = (CreativeService)user.GetService(DfpService.v201405.CreativeService);
            advertiserId    = utils.CreateCompany(user, CompanyType.ADVERTISER).id;
            creative1       = utils.CreateCreative(user, advertiserId);
            creative2       = utils.CreateCreative(user, advertiserId);
        }
Beispiel #9
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="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);

            // Create a Statement to get all image creatives.
            Statement statement = new StatementBuilder("WHERE creativeType = :creativeType LIMIT 500").
                                  AddValue("creativeType", "ImageCreative").ToStatement();

            try {
                // Get creatives by Statement.
                CreativePage page = creativeService.getCreativesByStatement(statement);

                if (page.results != null && page.results.Length > 0)
                {
                    Creative[] creatives = page.results;

                    // Update each local creative object by changing its destination URL.
                    foreach (Creative creative in creatives)
                    {
                        if (creative is ImageCreative)
                        {
                            ImageCreative imageCreative = (ImageCreative)creative;
                            imageCreative.destinationUrl = "http://news.google.com";
                        }
                    }

                    // Update the creatives on the server.
                    creatives = creativeService.updateCreatives(creatives);

                    if (creatives != null)
                    {
                        foreach (Creative creative in creatives)
                        {
                            if (creative is ImageCreative)
                            {
                                ImageCreative imageCreative = (ImageCreative)creative;
                                Console.WriteLine("An image creative with ID = '{0}' and destination URL ='{1}' " +
                                                  "was updated.", imageCreative.id, imageCreative.destinationUrl);
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("No creatives updated.");
                    }
                }
                else
                {
                    Console.WriteLine("No creatives found to update.");
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to update creatives. Exception says \"{0}\"", ex.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 LineItemCreativeAssociationService.
            LineItemCreativeAssociationService licaService =
                (LineItemCreativeAssociationService)user.GetService(
                    DfpService.v201311.LineItemCreativeAssociationService);

            // Get the CreativeService.
            CreativeService creativeService =
                (CreativeService)user.GetService(DfpService.v201311.CreativeService);

            // Set the line item ID and creative IDs to associate.
            long lineItemId = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE"));

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

            // Create an array to store local LICA objects.
            LineItemCreativeAssociation[] licas = new LineItemCreativeAssociation[creativeIds.Length];

            // For each line item, associate it with the given creative.
            int i = 0;

            foreach (long creativeId in creativeIds)
            {
                LineItemCreativeAssociation lica = new LineItemCreativeAssociation();
                lica.creativeId = creativeId;
                lica.lineItemId = lineItemId;
                licas[i++]      = lica;
            }

            try {
                // Create the LICAs on the server.
                licas = licaService.createLineItemCreativeAssociations(licas);

                if (licas != null)
                {
                    foreach (LineItemCreativeAssociation lica in licas)
                    {
                        Console.WriteLine("A LICA with line item ID \"{0}\", creative ID \"{1}\", and status " +
                                          "\"{2}\" was created.", lica.lineItemId, lica.creativeId, lica.status);
                    }
                }
                else
                {
                    Console.WriteLine("No LICAs created.");
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to associate creative with line item. Exception says \"{0}\"",
                                  ex.Message);
            }
        }
Beispiel #12
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 creative to update.
                long creativeId = long.Parse(_T("INSERT_CREATIVE_ID_HERE"));

                // Create a statement to get all image creatives.
                Statement statement = new StatementBuilder().Where("id = :id").OrderBy("id ASC")
                                      .Limit(1)
                                      .AddValue("id", creativeId).ToStatement();

                try
                {
                    // Get creatives by statement.
                    CreativePage page = creativeService.getCreativesByStatement(statement);

                    Creative creative = page.results[0];

                    // Update local creative object by changing its destination URL.
                    if (creative is ImageCreative)
                    {
                        ImageCreative imageCreative = (ImageCreative)creative;
                        imageCreative.destinationUrl = "http://news.google.com";
                    }

                    // Update the creatives on the server.
                    Creative[] creatives = creativeService.updateCreatives(new Creative[]
                    {
                        creative
                    });

                    foreach (Creative updatedCreative in creatives)
                    {
                        if (creative is ImageCreative)
                        {
                            ImageCreative imageCreative = (ImageCreative)updatedCreative;
                            Console.WriteLine(
                                "An image creative with ID = '{0}' and destination URL ='{1}' " +
                                "was updated.", imageCreative.id, imageCreative.destinationUrl);
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to update creatives. Exception says \"{0}\"",
                                      e.Message);
                }
            }
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser user)
        {
            CreativeService creativeService =
                (CreativeService)user.GetService(DfpService.v201605.CreativeService);

            // Create a statement to select creatives.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("creativeType = :creativeType")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("creativeType", "ImageCreative");

            // Retrieve a small amount of creatives at a time, paging through
            // until all creatives have been retrieved.
            CreativePage page = new CreativePage();

            try {
                do
                {
                    page = creativeService.getCreativesByStatement(statementBuilder.ToStatement());

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

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

                Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
            } catch (Exception e) {
                Console.WriteLine("Failed to get creatives. Exception says \"{0}\"",
                                  e.Message);
            }
        }
Beispiel #14
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(DfpUser dfpUser)
        {
            CreativeService creativeService =
                (CreativeService)dfpUser.GetService(DfpService.v201702.CreativeService);

            // Create a statement to select creatives.
            int pageSize = StatementBuilder.SUGGESTED_PAGE_LIMIT;
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("creativeType = :creativeType")
                                                .OrderBy("id ASC")
                                                .Limit(pageSize)
                                                .AddValue("creativeType", "ImageCreative");

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

            do
            {
                CreativePage page = creativeService.getCreativesByStatement(
                    statementBuilder.ToStatement());

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

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

            Console.WriteLine("Number of results found: {0}", totalResultSetSize);
        }
        /// <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.v201408.CreativeService);

            // Create a Statement to only select image creatives.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("creativeType = :creativeType")
                                                .OrderBy("id ASC")
                                                .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
                                                .AddValue("creativeType", "ImageCreative");

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

            try {
                do
                {
                    // Get creatives by Statement.
                    page = creativeService.getCreativesByStatement(statementBuilder.ToStatement());

                    if (page.results != null && page.results.Length > 0)
                    {
                        int i = page.startIndex;
                        foreach (Creative creative in page.results)
                        {
                            Console.WriteLine("{0}) Creative with ID ='{1}', name ='{2}' and type ='{3}' " +
                                              "was found.", i, creative.id, creative.name, creative.CreativeType);
                            i++;
                        }
                    }
                    statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
                } while (statementBuilder.GetOffset() < page.totalResultSetSize);

                Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
            } catch (Exception ex) {
                Console.WriteLine("Failed to get creatives by Statement. Exception says \"{0}\"",
                                  ex.Message);
            }
        }
Beispiel #16
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 defaults for page and Statement.
            CreativePage page      = new CreativePage();
            Statement    statement = new Statement();
            int          offset    = 0;

            try {
                do
                {
                    // Create a Statement to get all creatives.
                    statement.query = string.Format("LIMIT 500 OFFSET {0}", offset);

                    // Get creatives by Statement.
                    page = creativeService.getCreativesByStatement(statement);

                    if (page.results != null && page.results.Length > 0)
                    {
                        int i = page.startIndex;
                        foreach (Creative creative in page.results)
                        {
                            Console.WriteLine("{0}) Creative with ID ='{1}', name ='{2}' and type ='{3}' " +
                                              "was found.", i, creative.id, creative.name, creative.CreativeType);
                            i++;
                        }
                    }

                    offset += 500;
                } while (offset < page.totalResultSetSize);

                Console.WriteLine("Number of results found: {0}", page.totalResultSetSize);
            } catch (Exception ex) {
                Console.WriteLine("Failed to get all creatives. Exception says \"{0}\"", ex.Message);
            }
        }
Beispiel #17
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);
                }
            }
        }
Beispiel #18
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);
            }
        }
Beispiel #20
0
 public string GetCreative(CreativeView creative)
 {
     return(CreativeService.GetCreative(creative.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.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);
            }
        }
        /// <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.v201605.CreativeService);

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

            // Use the system defined native app install creative template.
            long creativeTemplateId = 10004400L;

            // Create a native app install creative for the Pie Noon app.
            TemplateCreative nativeAppInstallCreative = new TemplateCreative();

            nativeAppInstallCreative.name =
                String.Format("Native creative #{0}", new Random().Next(int.MaxValue));
            nativeAppInstallCreative.advertiserId       = advertiserId;
            nativeAppInstallCreative.creativeTemplateId = creativeTemplateId;
            nativeAppInstallCreative.destinationUrl     =
                "https://play.google.com/store/apps/details?id=com.google.fpl.pie_noon";

            // Use 1x1 as the size for native creatives.
            Size size = new Size();

            size.width                    = 1;
            size.height                   = 1;
            size.isAspectRatio            = false;
            nativeAppInstallCreative.size = size;

            List <BaseCreativeTemplateVariableValue> templateVariables =
                new List <BaseCreativeTemplateVariableValue>();

            // Set the headline.
            templateVariables.Add(new StringCreativeTemplateVariableValue()
            {
                uniqueName = "Headline",
                value      = "Pie Noon"
            });

            // Set the body text.
            templateVariables.Add(new StringCreativeTemplateVariableValue()
            {
                uniqueName = "Body",
                value      = "Try multi-screen mode!"
            });

            // Set the image asset.
            templateVariables.Add(new AssetCreativeTemplateVariableValue()
            {
                uniqueName = "Image",
                asset      = new CreativeAsset()
                {
                    fileName       = String.Format("image{0}.png", this.GetTimeStamp()),
                    assetByteArray = MediaUtilities.GetAssetDataFromUrl("https://lh4.ggpht.com/"
                                                                        + "GIGNKdGHMEHFDw6TM2bgAUDKPQQRIReKZPqEpMeEhZOPYnTdOQGaSpGSEZflIFs0iw=h300")
                }
            });

            // Set the price.
            templateVariables.Add(new StringCreativeTemplateVariableValue()
            {
                uniqueName = "Price",
                value      = "Free"
            });

            // Set app icon image asset.
            templateVariables.Add(new AssetCreativeTemplateVariableValue()
            {
                uniqueName = "Appicon",
                asset      = new CreativeAsset()
                {
                    fileName       = String.Format("icon{0}.png", this.GetTimeStamp()),
                    assetByteArray = MediaUtilities.GetAssetDataFromUrl("https://lh6.ggpht.com/"
                                                                        + "Jzvjne5CLs6fJ1MHF-XeuUfpABzl0YNMlp4RpHnvPRCIj4--eTDwtyouwUDzVVekXw=w300")
                }
            });

            // Set the call to action text.
            templateVariables.Add(new StringCreativeTemplateVariableValue()
            {
                uniqueName = "Calltoaction",
                value      = "Install"
            });

            // Set the star rating.
            templateVariables.Add(new StringCreativeTemplateVariableValue()
            {
                uniqueName = "Starrating",
                value      = "4"
            });

            // Set the store type.
            templateVariables.Add(new StringCreativeTemplateVariableValue()
            {
                uniqueName = "Store",
                value      = "Google Play"
            });

            // Set the deep link URL.
            templateVariables.Add(new UrlCreativeTemplateVariableValue()
            {
                uniqueName = "DeeplinkclickactionURL",
                value      = "market://details?id=com.google.fpl.pie_noon"
            });

            nativeAppInstallCreative.creativeTemplateVariableValues = templateVariables.ToArray();

            try {
                // Create the native creative on the server.
                Creative[] createdNativeCreatives = creativeService.createCreatives(
                    new Creative[] { nativeAppInstallCreative });

                foreach (Creative createdNativeCreative in createdNativeCreatives)
                {
                    Console.WriteLine("A native creative with ID \"{0}\" and name \"{1}\" " +
                                      "was created and can be previewed at {2}", createdNativeCreative.id,
                                      createdNativeCreative.name, createdNativeCreative.previewUrl);
                }
            } catch (Exception e) {
                Console.WriteLine("Failed to create creatives. Exception says \"{0}\"", e.Message);
            }
        }
Beispiel #23
0
 public void RedactChapter(Chapter redactChapter)
 {
     CreativeService.RedactChapter(redactChapter);
 }