/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="adGroupId">Id of the ad group to which ads are added. /// </param> public void Run(AdWordsUser user, long adGroupId) { // Get the AdGroupAdService. AdGroupAdService adGroupAdService = (AdGroupAdService)user.GetService(AdWordsService.v201506.AdGroupAdService); // Create the template ad. TemplateAd clickToDownloadAppAd = new TemplateAd(); clickToDownloadAppAd.name = "Ad for demo game"; clickToDownloadAppAd.templateId = 353; clickToDownloadAppAd.finalUrls = new string[] { "http://play.google.com/store/apps/details?id=com.example.demogame" }; clickToDownloadAppAd.displayUrl = "play.google.com"; // Create the template elements for the ad. You can refer to // https://developers.google.com/adwords/api/docs/appendix/templateads // for the list of avaliable template fields. TemplateElementField headline = new TemplateElementField(); headline.name = "headline"; headline.fieldText = "Enjoy your drive in Mars"; headline.type = TemplateElementFieldType.TEXT; TemplateElementField description1 = new TemplateElementField(); description1.name = "description1"; description1.fieldText = "Realistic physics simulation"; description1.type = TemplateElementFieldType.TEXT; TemplateElementField description2 = new TemplateElementField(); description2.name = "description2"; description2.fieldText = "Race against players online"; description2.type = TemplateElementFieldType.TEXT; TemplateElementField appId = new TemplateElementField(); appId.name = "appId"; appId.fieldText = "com.example.demogame"; appId.type = TemplateElementFieldType.TEXT; TemplateElementField appStore = new TemplateElementField(); appStore.name = "appStore"; appStore.fieldText = "2"; appStore.type = TemplateElementFieldType.ENUM; TemplateElement adData = new TemplateElement(); adData.uniqueName = "adData"; adData.fields = new TemplateElementField[] { headline, description1, description2, appId, appStore }; clickToDownloadAppAd.templateElements = new TemplateElement[] { adData }; // Create the adgroupad. AdGroupAd clickToDownloadAppAdGroupAd = new AdGroupAd(); clickToDownloadAppAdGroupAd.adGroupId = adGroupId; clickToDownloadAppAdGroupAd.ad = clickToDownloadAppAd; // Optional: Set the status. clickToDownloadAppAdGroupAd.status = AdGroupAdStatus.PAUSED; // Create the operation. AdGroupAdOperation operation = new AdGroupAdOperation(); operation.@operator = Operator.ADD; operation.operand = clickToDownloadAppAdGroupAd; try { // Create the ads. AdGroupAdReturnValue retval = adGroupAdService.mutate(new AdGroupAdOperation[] { operation }); // Display the results. if (retval != null && retval.value != null) { foreach (AdGroupAd adGroupAd in retval.value) { Console.WriteLine("New click-to-download ad with id = \"{0}\" and url = \"{1}\" " + "was created.", adGroupAd.ad.id, adGroupAd.ad.finalUrls[0]); } } else { Console.WriteLine("No click-to-download ads were created."); } } catch (Exception e) { throw new System.ApplicationException("Failed to create click-to-download ad.", e); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="adGroupId">Id of the first adgroup to which ad is added.</param> public void Run(AdWordsUser user, long adGroupId) { using (AdGroupAdService adGroupAdService = (AdGroupAdService)user.GetService(AdWordsService.v201809.AdGroupAdService)) { // Create the HTML5 template ad. See // https://developers.google.com/adwords/api/docs/guides/template-ads#html5_ads // for more details. TemplateAd html5Ad = new TemplateAd() { name = "Ad for HTML5", templateId = 419, finalUrls = new string[] { "http://example.com/html5" }, displayUrl = "www.example.com/html5", dimensions = new Dimensions() { width = 300, height = 250 } }; // The HTML5 zip file contains all the HTML, CSS, and images needed for the // HTML5 ad. For help on creating an HTML5 zip file, check out Google Web // Designer (https://www.google.com/webdesigner/). byte[] html5Zip = MediaUtilities.GetAssetDataFromUrl("https://goo.gl/9Y7qI2", user.Config); // Create a media bundle containing the zip file with all the HTML5 components. MediaBundle mediaBundle = new MediaBundle() { // You may also upload an HTML5 zip using MediaService.upload() method // set the mediaId field. See UploadMediaBundle.cs for an example on // how to upload HTML5 zip files. data = html5Zip, entryPoint = "carousel/index.html", type = MediaMediaType.MEDIA_BUNDLE }; // Create the template elements for the ad. You can refer to // https://developers.google.com/adwords/api/docs/appendix/templateads // for the list of available template fields. html5Ad.templateElements = new TemplateElement[] { new TemplateElement() { uniqueName = "adData", fields = new TemplateElementField[] { new TemplateElementField() { name = "Custom_layout", fieldMedia = mediaBundle, type = TemplateElementFieldType.MEDIA_BUNDLE }, new TemplateElementField() { name = "layout", fieldText = "Custom", type = TemplateElementFieldType.ENUM }, }, } }; // Create the AdGroupAd. AdGroupAd html5AdGroupAd = new AdGroupAd() { adGroupId = adGroupId, ad = html5Ad, // Additional properties (non-required). status = AdGroupAdStatus.PAUSED }; AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation() { @operator = Operator.ADD, operand = html5AdGroupAd }; try { // Add HTML5 ad. AdGroupAdReturnValue result = adGroupAdService.mutate(new AdGroupAdOperation[] { adGroupAdOperation }); // Display results. if (result != null && result.value != null && result.value.Length > 0) { foreach (AdGroupAd adGroupAd in result.value) { Console.WriteLine( "New HTML5 ad with id \"{0}\" and display url \"{1}\" was added.", adGroupAd.ad.id, adGroupAd.ad.displayUrl); } } else { Console.WriteLine("No HTML5 ads were added."); } } catch (Exception e) { throw new System.ApplicationException("Failed to create HTML5 ad.", e); } } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="adGroupId">Id of the first adgroup to which ad is added.</param> public void Run(AdWordsUser user, long adGroupId) { // Get the AdGroupAdService. AdGroupAdService adGroupAdService = (AdGroupAdService) user.GetService( AdWordsService.v201601.AdGroupAdService); // Create the HTML5 template ad. See // https://developers.google.com/adwords/api/docs/guides/template-ads#html5_ads // for more details. TemplateAd html5Ad = new TemplateAd() { name = "Ad for HTML5", templateId = 419, finalUrls = new string[] { "http://example.com/html5" }, displayUrl = "www.example.com/html5", dimensions = new Dimensions() { width = 300, height = 250 } }; // The HTML5 zip file contains all the HTML, CSS, and images needed for the // HTML5 ad. For help on creating an HTML5 zip file, check out Google Web // Designer (https://www.google.com/webdesigner/). byte[] html5Zip = MediaUtilities.GetAssetDataFromUrl("https://goo.gl/9Y7qI2"); // Create a media bundle containing the zip file with all the HTML5 components. MediaBundle mediaBundle = new MediaBundle() { // You may also upload an HTML5 zip using MediaService.upload() method // set the mediaId field. See UploadMediaBundle.cs for an example on // how to upload HTML5 zip files. data = html5Zip, entryPoint = "carousel/index.html", type = MediaMediaType.MEDIA_BUNDLE }; // Create the template elements for the ad. You can refer to // https://developers.google.com/adwords/api/docs/appendix/templateads // for the list of available template fields. html5Ad.templateElements = new TemplateElement[] { new TemplateElement() { uniqueName = "adData", fields = new TemplateElementField[] { new TemplateElementField() { name = "Custom_layout", fieldMedia = mediaBundle, type = TemplateElementFieldType.MEDIA_BUNDLE }, new TemplateElementField() { name = "layout", fieldText = "Custom", type = TemplateElementFieldType.ENUM }, }, } }; // Create the AdGroupAd. AdGroupAd html5AdGroupAd = new AdGroupAd() { adGroupId = adGroupId, ad = html5Ad, // Additional properties (non-required). status = AdGroupAdStatus.PAUSED }; AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation() { @operator = Operator.ADD, operand = html5AdGroupAd }; try { // Add HTML5 ad. AdGroupAdReturnValue result = adGroupAdService.mutate(new AdGroupAdOperation[] { adGroupAdOperation }); // Display results. if (result != null && result.value != null && result.value.Length > 0) { foreach (AdGroupAd adGroupAd in result.value) { Console.WriteLine("New HTML5 ad with id \"{0}\" and display url \"{1}\" was added.", adGroupAd.ad.id, adGroupAd.ad.displayUrl); } } else { Console.WriteLine("No HTML5 ads were added."); } } catch (Exception e) { throw new System.ApplicationException("Failed to create HTML5 ad.", e); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="adGroupId">Id of the ad group to which ads are added. /// </param> public void Run(AdWordsUser user, long adGroupId) { using (AdGroupAdService adGroupAdService = (AdGroupAdService)user.GetService(AdWordsService.v201806.AdGroupAdService)) { // Create the template ad. TemplateAd clickToDownloadAppAd = new TemplateAd { name = "Ad for demo game", templateId = 353, finalUrls = new string[] { "http://play.google.com/store/apps/details?id=com.example.demogame" }, displayUrl = "play.google.com" }; // Create the template elements for the ad. You can refer to // https://developers.google.com/adwords/api/docs/appendix/templateads // for the list of avaliable template fields. TemplateElementField headline = new TemplateElementField { name = "headline", fieldText = "Enjoy your drive in Mars", type = TemplateElementFieldType.TEXT }; TemplateElementField description1 = new TemplateElementField { name = "description1", fieldText = "Realistic physics simulation", type = TemplateElementFieldType.TEXT }; TemplateElementField description2 = new TemplateElementField { name = "description2", fieldText = "Race against players online", type = TemplateElementFieldType.TEXT }; TemplateElementField appId = new TemplateElementField { name = "appId", fieldText = "com.example.demogame", type = TemplateElementFieldType.TEXT }; TemplateElementField appStore = new TemplateElementField { name = "appStore", fieldText = "2", type = TemplateElementFieldType.ENUM }; // Optionally specify a landscape image. The image needs to be in a BASE64 // encoded form. Here we download a demo image and encode it for this ad. byte[] imageData = MediaUtilities.GetAssetDataFromUrl("https://goo.gl/9JmyKk", user.Config); Image image = new Image { data = imageData }; TemplateElementField landscapeImage = new TemplateElementField { name = "landscapeImage", fieldMedia = image, type = TemplateElementFieldType.IMAGE }; TemplateElement adData = new TemplateElement { uniqueName = "adData", fields = new TemplateElementField[] { headline, description1, description2, appId, appStore, landscapeImage } }; clickToDownloadAppAd.templateElements = new TemplateElement[] { adData }; // Create the adgroupad. AdGroupAd clickToDownloadAppAdGroupAd = new AdGroupAd { adGroupId = adGroupId, ad = clickToDownloadAppAd, // Optional: Set the status. status = AdGroupAdStatus.PAUSED }; // Create the operation. AdGroupAdOperation operation = new AdGroupAdOperation { @operator = Operator.ADD, operand = clickToDownloadAppAdGroupAd }; try { // Create the ads. AdGroupAdReturnValue retval = adGroupAdService.mutate(new AdGroupAdOperation[] { operation }); // Display the results. if (retval != null && retval.value != null) { foreach (AdGroupAd adGroupAd in retval.value) { Console.WriteLine( "New click-to-download ad with id = \"{0}\" and url = \"{1}\" " + "was created.", adGroupAd.ad.id, adGroupAd.ad.finalUrls[0]); } } else { Console.WriteLine("No click-to-download ads were created."); } } catch (Exception e) { throw new System.ApplicationException("Failed to create click-to-download ad.", e); } } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="adGroupId">Id of the ad group to which ads are added. /// </param> public void Run(AdWordsUser user, long adGroupId) { // Get the AdGroupAdService. AdGroupAdService adGroupAdService = (AdGroupAdService) user.GetService(AdWordsService.v201509.AdGroupAdService); // Create the template ad. TemplateAd clickToDownloadAppAd = new TemplateAd(); clickToDownloadAppAd.name = "Ad for demo game"; clickToDownloadAppAd.templateId = 353; clickToDownloadAppAd.finalUrls = new string[] { "http://play.google.com/store/apps/details?id=com.example.demogame" }; clickToDownloadAppAd.displayUrl = "play.google.com"; // Create the template elements for the ad. You can refer to // https://developers.google.com/adwords/api/docs/appendix/templateads // for the list of avaliable template fields. TemplateElementField headline = new TemplateElementField(); headline.name = "headline"; headline.fieldText = "Enjoy your drive in Mars"; headline.type = TemplateElementFieldType.TEXT; TemplateElementField description1 = new TemplateElementField(); description1.name = "description1"; description1.fieldText = "Realistic physics simulation"; description1.type = TemplateElementFieldType.TEXT; TemplateElementField description2 = new TemplateElementField(); description2.name = "description2"; description2.fieldText = "Race against players online"; description2.type = TemplateElementFieldType.TEXT; TemplateElementField appId = new TemplateElementField(); appId.name = "appId"; appId.fieldText = "com.example.demogame"; appId.type = TemplateElementFieldType.TEXT; TemplateElementField appStore = new TemplateElementField(); appStore.name = "appStore"; appStore.fieldText = "2"; appStore.type = TemplateElementFieldType.ENUM; TemplateElement adData = new TemplateElement(); adData.uniqueName = "adData"; adData.fields = new TemplateElementField[] {headline, description1, description2, appId, appStore}; clickToDownloadAppAd.templateElements = new TemplateElement[] {adData}; // Create the adgroupad. AdGroupAd clickToDownloadAppAdGroupAd = new AdGroupAd(); clickToDownloadAppAdGroupAd.adGroupId = adGroupId; clickToDownloadAppAdGroupAd.ad = clickToDownloadAppAd; // Optional: Set the status. clickToDownloadAppAdGroupAd.status = AdGroupAdStatus.PAUSED; // Create the operation. AdGroupAdOperation operation = new AdGroupAdOperation(); operation.@operator = Operator.ADD; operation.operand = clickToDownloadAppAdGroupAd; try { // Create the ads. AdGroupAdReturnValue retval = adGroupAdService.mutate(new AdGroupAdOperation[] {operation}); // Display the results. if (retval != null && retval.value != null) { foreach (AdGroupAd adGroupAd in retval.value) { Console.WriteLine("New click-to-download ad with id = \"{0}\" and url = \"{1}\" " + "was created.", adGroupAd.ad.id, adGroupAd.ad.finalUrls[0]); } } else { Console.WriteLine("No click-to-download ads were created."); } } catch (Exception e) { throw new System.ApplicationException("Failed to create click-to-download ad.", e); } }