/// <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.v201211.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++) {
            ImageCreative imageCreative = new ImageCreative();
            imageCreative.name = string.Format("Image creative #{0}", i);
            imageCreative.advertiserId = advertiserId;
            imageCreative.destinationUrl = "http://www.google.com";
            imageCreative.imageName = "image.jpg";
            imageCreative.imageByteArray = MediaUtilities.GetAssetDataFromUrl(
            "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg");

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

            imageCreative.size = imageSize;
            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.CreativeType);
            }
              }
            } else {
              Console.WriteLine("No creatives created.");
            }
              } catch (Exception ex) {
            Console.WriteLine("Failed to create creatives. Exception says \"{0}\"", ex.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");
    }
        public void TestCreateCreatives()
        {
            ImageCreative imageCreative1 = new ImageCreative();
              imageCreative1.name = string.Format("Image creative #{0}", new TestUtils().GetTimeStamp());
              imageCreative1.advertiserId = advertiserId;
              imageCreative1.destinationUrl = "http://www.google.com";
              imageCreative1.imageName = "image.jpg";
              imageCreative1.imageByteArray = MediaUtilities.GetAssetDataFromUrl(
              "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg");

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

              imageCreative1.size = imageSize1;

              ImageCreative imageCreative2 = new ImageCreative();
              imageCreative2.name = string.Format("Image creative #{0}", new TestUtils().GetTimeStamp());
              imageCreative2.advertiserId = advertiserId;
              imageCreative2.destinationUrl = "http://www.google.com";
              imageCreative2.imageName = "image.jpg";
              imageCreative2.imageByteArray = MediaUtilities.GetAssetDataFromUrl(
              "http://www.google.com/intl/en/adwords/select/images/samples/skyscraper.jpg");

              Size imageSize2 = new Size();
              imageSize2.width = 120;
              imageSize2.height = 600;

              imageCreative2.size = imageSize2;

              Creative[] newCreatives = null;

              Assert.DoesNotThrow(delegate() {
            newCreatives = creativeService.createCreatives(new Creative[] {imageCreative1,
            imageCreative2});
              });

              Assert.NotNull(newCreatives);
              Assert.AreEqual(newCreatives.Length, 2);
              Assert.NotNull(newCreatives[0]);
              Assert.That(newCreatives[0] is ImageCreative);
              Assert.AreEqual(newCreatives[0].advertiserId, imageCreative1.advertiserId);
              Assert.AreEqual(newCreatives[0].name, imageCreative1.name);
              Assert.NotNull(newCreatives[1]);
              Assert.That(newCreatives[1] is ImageCreative);
              Assert.AreEqual(newCreatives[1].advertiserId, imageCreative2.advertiserId);
              Assert.AreEqual(newCreatives[1].name, imageCreative2.name);
        }
        public void TestCreateCreative()
        {
            ImageCreative imageCreative = new ImageCreative();
              imageCreative.name = string.Format("Image creative #{0}", new TestUtils().GetTimeStamp());
              imageCreative.advertiserId = advertiserId;
              imageCreative.destinationUrl = "http://www.google.com";
              imageCreative.imageName = "image.jpg";
              imageCreative.imageByteArray = MediaUtilities.GetAssetDataFromUrl(
              "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg");

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

              imageCreative.size = imageSize;

              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);
        }
Exemplo n.º 5
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.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];
        }
Exemplo n.º 6
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.v201208.CreativeService);
              ImageCreative imageCreative = new ImageCreative();
              imageCreative.name = string.Format("Image creative #{0}", GetTimeStamp());
              imageCreative.advertiserId = advertiserId;
              imageCreative.destinationUrl = "http://www.google.com";
              imageCreative.imageName = "image.jpg";
              imageCreative.imageByteArray = MediaUtilities.GetAssetDataFromUrl(
              "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg");

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

              imageCreative.size = imageSize;

              return creativeService.createCreative(imageCreative);
        }
Exemplo n.º 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 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);
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(AdManagerUser user)
        {
            using (CreativeService creativeService = user.GetService <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, user.Config);

                        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);
                }
            }
        }
		private Ad CreateAd(CsvDynamicReader adsReader)
		{
			//--------------
			// Ad
			//--------------
			var ad = new Ad
			{
				OriginalID = adsReader.Current[AdWordsConst.AdIDFieldName],
				Channel = GetChannel("Google"),
				Account = GetAccount("Bbinary"),
				Fields = new Dictionary<EdgeField, object>(),
				TK = adsReader.Current[AdWordsConst.AdIDFieldName],
				EdgeType = GetEdgeType("Ad")
			};

			//--------------
			// Ad Type
			//--------------
			var adTypeValue = adsReader.Current[AdWordsConst.AdTypeFieldName].ToString();
			var devicePreferenceColumnValue = adsReader.Current[AdWordsConst.AdDevicePreferenceFieldName].ToString();
			
			//is mobile ad ? 
			if (devicePreferenceColumnValue.Equals(AdWordsConst.AdDevicePreferenceMobileFieldValue))
				adTypeValue = string.Format("Mobile {0}", adTypeValue);

			ad.Fields.Add(GetExtraField("AdType"), new StringValue
				{
					Value = adTypeValue,
					TK = adTypeValue,
					EdgeType = GetEdgeType("AdType")
				});

			//------------------
			// Destination Url
			//------------------
			if (!String.IsNullOrWhiteSpace(adsReader.Current[AdWordsConst.DestUrlFieldName]))
				ad.MatchDestination = new Destination
			{
				Value = adsReader.Current[AdWordsConst.DestUrlFieldName],
				TK = adsReader.Current[AdWordsConst.DestUrlFieldName],
				EdgeType = GetEdgeType("Destination")
			};

			//--------------
			// Campaign
			//--------------
			var campaign = new Campaign
			{
				Name = adsReader.Current[AdWordsConst.CampaignFieldName],
				OriginalID = adsReader.Current[AdWordsConst.CampaignIdFieldName],
				TK = adsReader.Current[AdWordsConst.CampaignIdFieldName],
				EdgeType = GetEdgeType("Campaign")
			};
			ad.Fields.Add(GetExtraField("Campaign"), campaign);

			//--------------
			// Ad group
			//--------------
			var adGroup = new StringValue
			{
				Value = adsReader.Current[AdWordsConst.AdGroupFieldName],
				OriginalID = adsReader.Current[AdWordsConst.AdGroupIdFieldName],
				Fields = new Dictionary<EdgeField, object>(),
				TK = adsReader.Current[AdWordsConst.AdGroupIdFieldName],
				EdgeType = GetEdgeType("AdGroup")
			};
			adGroup.Fields.Add(GetExtraField("Campaign"), campaign);
			ad.Fields.Add(GetExtraField("AdGroup"), adGroup);

			//---------------------
			// Composite Creatives
			//---------------------
			// composite creative and composite creative definition
			var compCreative = new CompositeCreative
			{
				Parts = new Dictionary<CompositePartField, SingleCreative>(),
				EdgeType = GetEdgeType("CompositeCreative")
			};
			var compCreativeMatch = new CompositeCreativeMatch
			{
				CreativesMatches = new Dictionary<CompositePartField, SingleCreativeMatch>(),
				Creative = compCreative,
				EdgeType = GetEdgeType("CompositeCreativeMatch")
			};

			//----------------------------------
			// Display Url as text creative
			//----------------------------------
			SingleCreative creative = new TextCreative
			{
				Text = adsReader.Current[AdWordsConst.DisplayURLFieldName],
				//TextCreativeType = new TextCreativeType 
				//{ 
				//	Value = "Url", 
				//	TK =  "Url",
				//	EdgeType = GetEdgeType("TextCreativeType")
				//},
				EdgeType = GetEdgeType("TextCreative"),
				TK = String.Format("{0}_{1}", "Url", adsReader.Current[AdWordsConst.DisplayURLFieldName])
			};
			compCreative.Parts.Add(GetCompositePartField("DisplayUrlCreative"), creative);

			SingleCreativeMatch match = new TextCreativeMatch
			{
				Creative = creative,
				EdgeType = GetEdgeType("TextCreativeMatch"),
				TK = adsReader.Current[AdWordsConst.DisplayURLFieldName]
			};
			compCreativeMatch.CreativesMatches.Add(GetCompositePartField("DisplayUrlMatch"), match);

			if (String.Equals(Convert.ToString(adsReader.Current[AdWordsConst.AdTypeFieldName]), "Image ad"))
			{
				//----------------------------------
				// Image as Image creative
				//----------------------------------
				// format for example: Ad name: 468_60_Test7options_Romanian.swf; 468 x 60
				var imageParams = adsReader.Current[AdWordsConst.AdFieldName].Trim().Split(new[] { ':', ';' });

				creative = new ImageCreative
				{
					Image = imageParams[1].Trim(),
					EdgeType = GetEdgeType("ImageCreative"),
					TK = imageParams[1].Trim()
				};
				compCreative.Parts.Add(GetCompositePartField("SingleCreative"), creative);

				match = new ImageCreativeMatch
				{
					Creative = creative,
					ImageSize = imageParams[2].Trim(),
					EdgeType = GetEdgeType("ImageCreativeDefinition"),
					TK = String.Format("{0}_{1}", imageParams[1].Trim(), imageParams[2].Trim())
				};
				compCreativeMatch.CreativesMatches.Add(GetCompositePartField("SingleCreativeMatch"), match);
			}
			else
			{
				//----------------------------------
				// Title as Text creative
				//----------------------------------
				creative = new TextCreative
				{
					Text = adsReader.Current.Ad,
					//TextCreativeType = new TextCreativeType
					//{
					//	Value = "Text",
					//	TK = "Text",
					//	EdgeType = GetEdgeType("TextCreativeType")
					//},
					EdgeType = GetEdgeType("TextCreative"),
					TK = String.Format("{0}_{1}", "Text", adsReader.Current.Ad)
				};
				compCreative.Parts.Add(GetCompositePartField("SingleCreative"), creative);

				match = new TextCreativeMatch
				{
					Creative = creative,
					EdgeType = GetEdgeType("TextCreativeMatch"),
					TK = adsReader.Current.Ad
				};
				compCreativeMatch.CreativesMatches.Add(GetCompositePartField("SingleCreativeMatch"), match);

				//----------------------------------
				// Description 1 as Text creative
				//----------------------------------
				creative = new TextCreative
				{
					Text = adsReader.Current["Description line 1"],
					//TextCreativeType = new TextCreativeType
					//{
					//	Value = "Text",
					//	TK = "Text",
					//	EdgeType = GetEdgeType("TextCreativeType")
					//},
					EdgeType = GetEdgeType("TextCreative"),
					TK = String.Format("{0}_{1}", "Text", adsReader.Current["Description line 1"])
				};
				compCreative.Parts.Add(GetCompositePartField("Desc1Creative"), creative);

				match = new TextCreativeMatch
				{
					Creative = creative,
					EdgeType = GetEdgeType("TextCreativeMatch"),
					TK = adsReader.Current["Description line 1"]
				};
				compCreativeMatch.CreativesMatches.Add(GetCompositePartField("Desc1Definition"), match);

				//----------------------------------
				// Description 2 as Text creative
				//----------------------------------
				creative = new TextCreative
				{
					Text = adsReader.Current["Description line 2"],
					//TextCreativeType = new TextCreativeType
					//{
					//	Value = "Text",
					//	TK = "Text",
					//	EdgeType = GetEdgeType("TextCreativeType")
					//},
					EdgeType = GetEdgeType("TextCreative"),
					TK = String.Format("{0}_{1}", "Text", adsReader.Current["Description line 2"])
				};
				compCreative.Parts.Add(GetCompositePartField("Desc2Creative"), creative);

				match = new TextCreativeMatch
				{
					Creative = creative,
					EdgeType = GetEdgeType("TextCreativeMatch"),
					TK = adsReader.Current["Description line 2"]
				};
				compCreativeMatch.CreativesMatches.Add(GetCompositePartField("Desc2Definition"), match);
			}

			SetCompositeCreativeTk(compCreative);
			SetCompositeCreativeDefinitionTk(compCreativeMatch);
			ad.CreativeMatch = compCreativeMatch;
			ad.CreativeMatch.Creative = compCreative;

			// add Ad to cache of Ads
			_importedAds.Add(ad.OriginalID, ad);
			return ad;
		}