/// <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); } }
/// <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); } }
/// <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); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The DFP user object running the code example.</param> public override void Run(DfpUser user) { // Get the CreativeService. CreativeService creativeService = (CreativeService) user.GetService(DfpService.v201511.CreativeService); // Set the ID of the advertiser (company) that 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; // 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); } }