예제 #1
0
        /// <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.v201705.AdGroupAdService)) {
                try {
                    // Create a responsive display ad.
                    ResponsiveDisplayAd responsiveDisplayAd = new ResponsiveDisplayAd();

                    // This ad format does not allow the creation of an image using the
                    // Image.data field. An image must first be created using the MediaService,
                    // and Image.mediaId must be populated when creating the ad.
                    responsiveDisplayAd.marketingImage = new Image()
                    {
                        mediaId = UploadImage(user, "https://goo.gl/3b9Wfh")
                    };
                    responsiveDisplayAd.shortHeadline = "Travel";
                    responsiveDisplayAd.longHeadline  = "Travel the World";
                    responsiveDisplayAd.description   = "Take to the air!";
                    responsiveDisplayAd.businessName  = "Google";
                    responsiveDisplayAd.finalUrls     = new string[] { "http://www.example.com" };

                    // Create ad group ad.
                    AdGroupAd adGroupAd = new AdGroupAd()
                    {
                        adGroupId = adGroupId,
                        ad        = responsiveDisplayAd,
                        status    = AdGroupAdStatus.PAUSED
                    };

                    // Create operation.
                    AdGroupAdOperation operation = new AdGroupAdOperation()
                    {
                        operand   = adGroupAd,
                        @operator = Operator.ADD
                    };

                    // Make the mutate request.
                    AdGroupAdReturnValue result = adGroupAdService.mutate(
                        new AdGroupAdOperation[] { operation });

                    // Display results.
                    if (result != null && result.value != null)
                    {
                        foreach (AdGroupAd newAdGroupAd in result.value)
                        {
                            ResponsiveDisplayAd newAd = newAdGroupAd.ad as ResponsiveDisplayAd;
                            Console.WriteLine("Responsive display ad with ID '{0}' and short headline '{1}'" +
                                              " was added.", newAd.id, newAd.shortHeadline);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No responsive display ads were created.");
                    }
                } catch (Exception e) {
                    throw new System.ApplicationException("Failed to create responsive display ad.", e);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Creates an ad for serving dynamic content in a remarketing campaign.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="adGroup">The ad group under which to create the ad.</param>
        /// <returns>The ad that was created.</returns>
        private static AdGroupAd CreateAd(AdWordsUser user, AdGroup adGroup)
        {
            using (AdGroupAdService adService = (AdGroupAdService)user.GetService(
                       AdWordsService.v201806.AdGroupAdService)) {
                ResponsiveDisplayAd ad = new ResponsiveDisplayAd {
                    // This ad format does not allow the creation of an image using the
                    // Image.data field. An image must first be created using the MediaService,
                    // and Image.mediaId must be populated when creating the ad.
                    marketingImage = UploadImage(user, "https://goo.gl/3b9Wfh"),

                    shortHeadline = "Travel",
                    longHeadline  = "Travel the World",
                    description   = "Take to the air!",
                    businessName  = "Interplanetary Cruises",
                    finalUrls     = new string[] { "http://www.example.com/" },

                    // Optional: Call to action text.
                    // Valid texts: https://support.google.com/adwords/answer/7005917
                    callToActionText = "Apply Now",

                    // Optional: Set dynamic display ad settings, composed of landscape logo
                    // image, promotion text, and price prefix.
                    dynamicDisplayAdSettings = CreateDynamicDisplayAdSettings(user),

                    // Optional: Create a logo image and set it to the ad.
                    logoImage = UploadImage(user, "https://goo.gl/mtt54n"),

                    // Optional: Create a square marketing image and set it to the ad.
                    squareMarketingImage = UploadImage(user, "https://goo.gl/mtt54n")
                };

                // Whitelisted accounts only: Set color settings using hexadecimal values.
                // Set allowFlexibleColor to false if you want your ads to render by always
                // using your colors strictly.
                // ad.mainColor = "#0000ff";
                // ad.accentColor = "#ffff00";
                // ad.allowFlexibleColor = false;

                // Whitelisted accounts only: Set the format setting that the ad will be
                // served in.
                // ad.formatSetting = DisplayAdFormatSetting.NON_NATIVE;

                AdGroupAd adGroupAd = new AdGroupAd {
                    ad        = ad,
                    adGroupId = adGroup.id
                };

                AdGroupAdOperation op = new AdGroupAdOperation {
                    operand   = adGroupAd,
                    @operator = Operator.ADD
                };

                AdGroupAdReturnValue result = adService.mutate(new AdGroupAdOperation[] { op });
                return(result.value[0]);
            }
        }
예제 #3
0
        /// <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.v201710.AdGroupAdService)) {
                try {
                    // Create a responsive display ad.
                    ResponsiveDisplayAd responsiveDisplayAd = new ResponsiveDisplayAd();

                    // This ad format does not allow the creation of an image using the
                    // Image.data field. An image must first be created using the MediaService,
                    // and Image.mediaId must be populated when creating the ad.
                    responsiveDisplayAd.marketingImage = new Image()
                    {
                        mediaId = UploadImage(user, "https://goo.gl/3b9Wfh")
                    };
                    responsiveDisplayAd.shortHeadline = "Travel";
                    responsiveDisplayAd.longHeadline  = "Travel the World";
                    responsiveDisplayAd.description   = "Take to the air!";
                    responsiveDisplayAd.businessName  = "Google";
                    responsiveDisplayAd.finalUrls     = new string[] { "http://www.example.com" };

                    // Optional: Create a square marketing image using MediaService, and set it
                    // to the ad.
                    responsiveDisplayAd.squareMarketingImage = new Image()
                    {
                        mediaId = UploadImage(user, "https://goo.gl/mtt54n"),
                    };

                    // Optional: set call to action text.
                    responsiveDisplayAd.callToActionText = "Shop Now";

                    // Optional: Set dynamic display ad settings, composed of landscape logo
                    // image, promotion text, and price prefix.
                    responsiveDisplayAd.dynamicDisplayAdSettings = CreateDynamicDisplayAdSettings(user);

                    // Whitelisted accounts only: Set color settings using hexadecimal values.
                    // Set allowFlexibleColor to false if you want your ads to render by always
                    // using your colors strictly.

                    // responsiveDisplayAd.mainColor = "#0000ff";
                    // responsiveDisplayAd.accentColor = "#ffff00";
                    // responsiveDisplayAd.allowFlexibleColor = false;

                    // Whitelisted accounts only: Set the format setting that the ad will be
                    // served in.

                    // responsiveDisplayAd.formatSetting = DisplayAdFormatSetting.NON_NATIVE;

                    // Create ad group ad.
                    AdGroupAd adGroupAd = new AdGroupAd()
                    {
                        adGroupId = adGroupId,
                        ad        = responsiveDisplayAd,
                        status    = AdGroupAdStatus.PAUSED
                    };

                    // Create operation.
                    AdGroupAdOperation operation = new AdGroupAdOperation()
                    {
                        operand   = adGroupAd,
                        @operator = Operator.ADD
                    };

                    // Make the mutate request.
                    AdGroupAdReturnValue result = adGroupAdService.mutate(
                        new AdGroupAdOperation[] { operation });

                    // Display results.
                    if (result != null && result.value != null)
                    {
                        foreach (AdGroupAd newAdGroupAd in result.value)
                        {
                            ResponsiveDisplayAd newAd = newAdGroupAd.ad as ResponsiveDisplayAd;
                            Console.WriteLine("Responsive display ad with ID '{0}' and short headline '{1}'" +
                                              " was added.", newAd.id, newAd.shortHeadline);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No responsive display ads were created.");
                    }
                } catch (Exception e) {
                    throw new System.ApplicationException("Failed to create responsive display ad.", e);
                }
            }
        }