Exemplo n.º 1
0
        /// <summary>
        /// Creates a new hotel ad group ad in the specified ad group.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="adGroupResourceName">The resource name of ad group that a new ad group
        /// ad will belong to</param>
        private static void AddHotelAdGroupAd(GoogleAdsClient client, long customerId,
                                              string adGroupResourceName)
        {
            // Get the AdGroupAdService.
            AdGroupAdServiceClient service = client.GetService(Services.V1.AdGroupAdService);

            // Create a new ad group ad and sets the hotel ad to it.
            AdGroupAd adGroupAd = new AdGroupAd()
            {
                // Create a new hotel ad.
                Ad = new Ad()
                {
                    HotelAd = new HotelAdInfo(),
                },
                // Set the ad group.
                AdGroup = adGroupResourceName,
                Status  = AdGroupAdStatus.Paused
            };

            // Create an ad group ad operation.
            AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation()
            {
                Create = adGroupAd
            };

            // Issue a mutate request to add an ad group ad.
            MutateAdGroupAdsResponse response = service.MutateAdGroupAds(customerId.ToString(),
                                                                         new AdGroupAdOperation[] { adGroupAdOperation });

            MutateAdGroupAdResult addedAdGroupAd = response.Results[0];

            Console.WriteLine($"Added a hotel ad group ad with resource name " +
                              $"{addedAdGroupAd.ResourceName}.");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="adGroupId">The ad group ID that contains the ad.</param>
        /// <param name="adId">ID of the ad to remove.</param>
        public void Run(GoogleAdsClient client, long customerId, long adGroupId, long adId)
        {
            // Get the AdGroupAdService.
            AdGroupAdServiceClient service = client.GetService(Services.V1.AdGroupAdService);

            // Create a new operation.
            AdGroupAdOperation operation = new AdGroupAdOperation
            {
                // Set the Remove field to the name of the resource to be removed.
                Remove = ResourceNames.AdGroupAd(customerId, adGroupId, adId)
            };

            try
            {
                // Remove the ad.
                MutateAdGroupAdsResponse response = service.MutateAdGroupAds(customerId.ToString(),
                                                                             new AdGroupAdOperation[] { operation });

                // Display the results.
                foreach (MutateAdGroupAdResult result in response.Results)
                {
                    Console.WriteLine($"Ad with resource name = {result.ResourceName} " +
                                      "was removed.");
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="adGroupId">ID of the ad group to which ads are added.</param>
        // [START AddExpandedTextAds]
        public void Run(GoogleAdsClient client, long customerId, long adGroupId)
        {
            // Get the AdGroupAdService.
            AdGroupAdServiceClient adGroupAdService = client.GetService(
                Services.V6.AdGroupAdService);

            List <AdGroupAdOperation> operations = new List <AdGroupAdOperation>();

            for (int i = 0; i < NUMBER_OF_ADS; i++)
            {
                // Create the ad group ad object.
                AdGroupAd adGroupAd = new AdGroupAd
                {
                    AdGroup = ResourceNames.AdGroup(customerId, adGroupId),
                    // Optional: Set the status.
                    Status = AdGroupAdStatus.Paused,
                    Ad     = new Ad
                    {
                        FinalUrls      = { "http://www.example.com/" + i },
                        ExpandedTextAd = new ExpandedTextAdInfo
                        {
                            Description   = "Buy your tickets now!",
                            HeadlinePart1 = "Cruise #" + i.ToString() + " to Mars",
                            HeadlinePart2 = "Best Space Cruise Line",
                            Path1         = "path1",
                            Path2         = "path2"
                        }
                    }
                };

                // Create the operation.
                operations.Add(new AdGroupAdOperation
                {
                    Create = adGroupAd
                });
            }

            try
            {
                // Create the ads.
                MutateAdGroupAdsResponse response = adGroupAdService.MutateAdGroupAds(
                    customerId.ToString(), operations);

                // Display the results.
                foreach (MutateAdGroupAdResult result in response.Results)
                {
                    Console.WriteLine("Expanded text ad created with resource name: {0}",
                                      result.ResourceName);
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
 /// <summary>Snippet for GetAdGroupAd</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetAdGroupAd()
 {
     // Create client
     AdGroupAdServiceClient adGroupAdServiceClient = AdGroupAdServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER_ID]/adGroupAds/[AD_GROUP_ID]~[AD_ID]";
     // Make the request
     AdGroupAd response = adGroupAdServiceClient.GetAdGroupAd(resourceName);
 }
Exemplo n.º 5
0
 /// <summary>Snippet for GetAdGroupAd</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetAdGroupAdResourceNames()
 {
     // Create client
     AdGroupAdServiceClient adGroupAdServiceClient = AdGroupAdServiceClient.Create();
     // Initialize request argument(s)
     AdGroupAdName resourceName = AdGroupAdName.FromCustomerAdGroupAd("[CUSTOMER]", "[AD_GROUP_AD]");
     // Make the request
     AdGroupAd response = adGroupAdServiceClient.GetAdGroupAd(resourceName);
 }
        /// <summary>Snippet for GetAdGroupAdAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetAdGroupAdAsync()
        {
            // Create client
            AdGroupAdServiceClient adGroupAdServiceClient = await AdGroupAdServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER]/adGroupAds/[AD_GROUP_AD]";
            // Make the request
            AdGroupAd response = await adGroupAdServiceClient.GetAdGroupAdAsync(resourceName);
        }
Exemplo n.º 7
0
        /// <summary>Snippet for GetAdGroupAdAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetAdGroupAdResourceNamesAsync()
        {
            // Create client
            AdGroupAdServiceClient adGroupAdServiceClient = await AdGroupAdServiceClient.CreateAsync();

            // Initialize request argument(s)
            AdGroupAdName resourceName = AdGroupAdName.FromCustomerAdGroupAd("[CUSTOMER_ID]", "[AD_GROUP_ID]", "[AD_ID]");
            // Make the request
            AdGroupAd response = await adGroupAdServiceClient.GetAdGroupAdAsync(resourceName);
        }
 /// <summary>Snippet for GetAdGroupAd</summary>
 public void GetAdGroupAd()
 {
     // Snippet: GetAdGroupAd(string, CallSettings)
     // Create client
     AdGroupAdServiceClient adGroupAdServiceClient = AdGroupAdServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER]/adGroupAds/[AD_GROUP_AD]";
     // Make the request
     AdGroupAd response = adGroupAdServiceClient.GetAdGroupAd(resourceName);
     // End snippet
 }
 /// <summary>Snippet for GetAdGroupAd</summary>
 public void GetAdGroupAdResourceNames()
 {
     // Snippet: GetAdGroupAd(AdGroupAdName, CallSettings)
     // Create client
     AdGroupAdServiceClient adGroupAdServiceClient = AdGroupAdServiceClient.Create();
     // Initialize request argument(s)
     AdGroupAdName resourceName = AdGroupAdName.FromCustomerAdGroupAd("[CUSTOMER_ID]", "[AD_GROUP_ID]", "[AD_ID]");
     // Make the request
     AdGroupAd response = adGroupAdServiceClient.GetAdGroupAd(resourceName);
     // End snippet
 }
 /// <summary>Snippet for GetAdGroupAd</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetAdGroupAdRequestObject()
 {
     // Create client
     AdGroupAdServiceClient adGroupAdServiceClient = AdGroupAdServiceClient.Create();
     // Initialize request argument(s)
     GetAdGroupAdRequest request = new GetAdGroupAdRequest
     {
         ResourceNameAsAdGroupAdName = AdGroupAdName.FromCustomerAdGroupAd("[CUSTOMER_ID]", "[AD_GROUP_ID]", "[AD_ID]"),
     };
     // Make the request
     AdGroupAd response = adGroupAdServiceClient.GetAdGroupAd(request);
 }
Exemplo n.º 11
0
        /// <summary>
        /// Adds the gmail ad.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="adGroupId">The ad group to which ads are added.</param>
        /// <param name="mediaFiles">The media files.</param>
        private void AddAd(GoogleAdsClient client, long customerId, long adGroupId,
                           Dictionary <string, string> mediaFiles)
        {
            // Get the AdGroupAdService.
            AdGroupAdServiceClient adGroupAdService =
                client.GetService(Services.V2.AdGroupAdService);

            // Creates the Gmail ad info.
            GmailAdInfo gmailAdInfo = new GmailAdInfo()
            {
                Teaser = new GmailTeaser()
                {
                    Headline     = "Dream",
                    Description  = "Create your own adventure",
                    BusinessName = "Interplanetary Ships",
                    LogoImage    = mediaFiles["logoResourceName"]
                },
                MarketingImage            = mediaFiles["marketingImageResourceName"],
                MarketingImageHeadline    = "Travel",
                MarketingImageDescription = "Take to the skies!"
            };

            // Creates the ad.
            Ad ad = new Ad()
            {
                Name      = "Gmail Ad #" + ExampleUtilities.GetRandomString(),
                FinalUrls = { "http://www.example.com" },
                GmailAd   = gmailAdInfo
            };

            // Creates the ad group ad.
            AdGroupAd adGroupAd = new AdGroupAd()
            {
                Ad      = ad,
                Status  = AdGroupAdStatus.Paused,
                AdGroup = ResourceNames.AdGroup(customerId, adGroupId)
            };

            // Create the operation.
            AdGroupAdOperation operation = new AdGroupAdOperation()
            {
                Create = adGroupAd
            };


            // Create the ad group ad.
            MutateAdGroupAdsResponse response =
                adGroupAdService.MutateAdGroupAds(customerId.ToString(), new[] { operation });

            // Display the results.
            Console.WriteLine($"Created ad group ad with resource name " +
                              $"'{response.Results[0].ResourceName}'.");
        }
        /// <summary>Snippet for GetAdGroupAdAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetAdGroupAdRequestObjectAsync()
        {
            // Create client
            AdGroupAdServiceClient adGroupAdServiceClient = await AdGroupAdServiceClient.CreateAsync();

            // Initialize request argument(s)
            GetAdGroupAdRequest request = new GetAdGroupAdRequest
            {
                ResourceNameAsAdGroupAdName = AdGroupAdName.FromCustomerAdGroupAd("[CUSTOMER]", "[AD_GROUP_AD]"),
            };
            // Make the request
            AdGroupAd response = await adGroupAdServiceClient.GetAdGroupAdAsync(request);
        }
 /// <summary>Snippet for MutateAdGroupAds</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void MutateAdGroupAds()
 {
     // Create client
     AdGroupAdServiceClient adGroupAdServiceClient = AdGroupAdServiceClient.Create();
     // Initialize request argument(s)
     string customerId = "";
     IEnumerable <AdGroupAdOperation> operations = new AdGroupAdOperation[]
     {
         new AdGroupAdOperation(),
     };
     // Make the request
     MutateAdGroupAdsResponse response = adGroupAdServiceClient.MutateAdGroupAds(customerId, operations);
 }
        /// <summary>Snippet for GetAdGroupAdAsync</summary>
        public async Task GetAdGroupAdResourceNamesAsync()
        {
            // Snippet: GetAdGroupAdAsync(AdGroupAdName, CallSettings)
            // Additional: GetAdGroupAdAsync(AdGroupAdName, CancellationToken)
            // Create client
            AdGroupAdServiceClient adGroupAdServiceClient = await AdGroupAdServiceClient.CreateAsync();

            // Initialize request argument(s)
            AdGroupAdName resourceName = AdGroupAdName.FromCustomerAdGroupAd("[CUSTOMER_ID]", "[AD_GROUP_ID]", "[AD_ID]");
            // Make the request
            AdGroupAd response = await adGroupAdServiceClient.GetAdGroupAdAsync(resourceName);

            // End snippet
        }
        /// <summary>Snippet for GetAdGroupAdAsync</summary>
        public async Task GetAdGroupAdAsync()
        {
            // Snippet: GetAdGroupAdAsync(string, CallSettings)
            // Additional: GetAdGroupAdAsync(string, CancellationToken)
            // Create client
            AdGroupAdServiceClient adGroupAdServiceClient = await AdGroupAdServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER_ID]/adGroupAds/[AD_GROUP_ID]~[AD_ID]";
            // Make the request
            AdGroupAd response = await adGroupAdServiceClient.GetAdGroupAdAsync(resourceName);

            // End snippet
        }
Exemplo n.º 16
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="adGroupId">The ad group ID that contains the ad.</param>
        /// <param name="adId">AdGroupAdService</param>
        public void Run(GoogleAdsClient client, long customerId, long adGroupId, long adId)
        {
            // Get the AdGroupAdService.
            AdGroupAdServiceClient adGroupAdService = client.GetService(
                Services.V4.AdGroupAdService);

            // Create the ad group ad.
            AdGroupAd adGroupAd = new AdGroupAd
            {
                ResourceName = ResourceNames.AdGroupAd(customerId, adGroupId, adId),
                Status       = AdGroupAdStatus.Paused
            };

            // Create the operation.
            AdGroupAdOperation operation = new AdGroupAdOperation
            {
                // Set the Update field to the ad group ad object.
                Update = adGroupAd,

                // Use the FieldMasks utility to set the UpdateMask field to  a list of all
                // modified fields of the ad group ad.
                UpdateMask = FieldMasks.AllSetFieldsOf(adGroupAd)
            };

            try
            {
                // Update the ad.
                MutateAdGroupAdsResponse response =
                    adGroupAdService.MutateAdGroupAds(customerId.ToString(),
                                                      new AdGroupAdOperation[] { operation });

                // Display the results.
                foreach (MutateAdGroupAdResult result in response.Results)
                {
                    Console.WriteLine($"Ad with resource name = {result.ResourceName} was " +
                                      "paused.");
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Creates expanded text ads that use the ad customizer feed to populate the placeholders.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="adGroupIds">The ad group IDs in which to create the ads.</param>
        /// <param name="feedName">Name of the feed.</param>
        private void CreateAdsWithCustomizations(GoogleAdsClient client, long customerId,
                                                 long[] adGroupIds, string feedName)
        {
            // Get the AdGroupAdServiceClient.
            AdGroupAdServiceClient adGroupAdService =
                client.GetService(Services.V4.AdGroupAdService);


            // Creates an expanded text ad using the feed attribute names as placeholders.
            Ad ad = new Ad()
            {
                ExpandedTextAd = new ExpandedTextAdInfo()
                {
                    HeadlinePart1 = $"Luxury cruise to {{={feedName}.Name}}",
                    HeadlinePart2 = $"Only {{={feedName}.Price}}",
                    Description   = $"Offer ends in {{=countdown({feedName}.Date)}}!"
                },
                FinalUrls = { "http://www.example.com" }
            };

            List <AdGroupAdOperation> adGroupAdOperations = new List <AdGroupAdOperation>();

            // Creates the same ad in all ad groups. When they serve, they will show
            // different values, since they match different feed items.
            foreach (long adGroupId in adGroupIds)
            {
                AdGroupAd adGroupAd = new AdGroupAd()
                {
                    Ad      = ad,
                    AdGroup = ResourceNames.AdGroup(customerId, adGroupId)
                };

                adGroupAdOperations.Add(new AdGroupAdOperation()
                {
                    Create = adGroupAd
                });
            }

            MutateAdGroupAdsResponse response =
                adGroupAdService.MutateAdGroupAds(customerId.ToString(), adGroupAdOperations);

            Console.WriteLine($"Added {response.Results.Count} ads:");
            foreach (MutateAdGroupAdResult result in response.Results)
            {
                Console.WriteLine($"Added an ad with resource name '{result.ResourceName}'.");
            }
        }
        /// <summary>
        /// Sends exemption requests for creating an expanded text ad.
        /// </summary>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="service">The ad group ad service.</param>
        /// <param name="operation">The ad group ad operation to request exemption for.</param>
        /// <param name="ignorablePolicyTopics">The ignorable policy topics.</param>
        private static void RequestExemption(long customerId, AdGroupAdServiceClient service,
                                             AdGroupAdOperation operation, string[] ignorablePolicyTopics)
        {
            Console.WriteLine("Try adding an expanded text ad again by requesting exemption for " +
                              "its policy violations.");
            PolicyValidationParameter validationParameter = new PolicyValidationParameter();

            validationParameter.IgnorablePolicyTopics.AddRange(ignorablePolicyTopics);
            operation.PolicyValidationParameter = validationParameter;

            MutateAdGroupAdsResponse response = service.MutateAdGroupAds(
                customerId.ToString(), new[] { operation });

            Console.WriteLine($"Successfully added an expanded text ad with resource name " +
                              $"'{response.Results[0].ResourceName}' by requesting for policy violation " +
                              $"exemption.");
        }
Exemplo n.º 19
0
        /// <summary>
        /// Creates a new HTML5 display upload ad and adds it to the specified ad group.
        /// </summary>
        /// <param name="client">The Google Ads API client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="adGroupId">The ID of the ad group to which the new ad will be
        ///     added.</param>
        /// <param name="adAssetResourceName">The resource name of the media bundle containing
        ///     the HTML5 components.</param>
        private void CreateDisplayUploadAdGroupAd(GoogleAdsClient client, long customerId,
                                                  long adGroupId, string adAssetResourceName)
        {
            // Get the AdGroupAdService.
            AdGroupAdServiceClient adGroupAdServiceClient =
                client.GetService(Services.V6.AdGroupAdService);

            // Creates the ad with the required fields.
            Ad displayUploadAd = new Ad()
            {
                Name      = "Ad for HTML5",
                FinalUrls = { "http://example.com/html5" },
                // Exactly one ad data field must be included to specify the ad type. See
                // https://developers.google.com/google-ads/api/reference/rpc/V6/Ad for the full
                // list of available types.
                DisplayUploadAd = new DisplayUploadAdInfo()
                {
                    DisplayUploadProductType = DisplayUploadProductType.Html5UploadAd,
                    MediaBundle = new AdMediaBundleAsset()
                    {
                        Asset = adAssetResourceName
                    }
                }
            };

            // Creates an ad group ad for the new ad.
            AdGroupAd adGroupAd = new AdGroupAd()
            {
                Ad      = displayUploadAd,
                Status  = AdGroupAdStatusEnum.Types.AdGroupAdStatus.Paused,
                AdGroup = ResourceNames.AdGroup(customerId, adGroupId),
            };

            // Creates the ad group ad operation.
            AdGroupAdOperation operation = new AdGroupAdOperation()
            {
                Create = adGroupAd
            };

            // Adds the ad group ad to the client account.
            MutateAdGroupAdsResponse response = adGroupAdServiceClient.MutateAdGroupAds
                                                    (customerId.ToString(), new[] { operation });

            // Displays the resulting ad group ad's resource name.
            Console.WriteLine($"Created new ad group ad{response.Results.First().ResourceName}.");
        }
        /// <summary>Snippet for MutateAdGroupAdsAsync</summary>
        public async Task MutateAdGroupAdsAsync()
        {
            // Snippet: MutateAdGroupAdsAsync(string, IEnumerable<AdGroupAdOperation>, CallSettings)
            // Additional: MutateAdGroupAdsAsync(string, IEnumerable<AdGroupAdOperation>, CancellationToken)
            // Create client
            AdGroupAdServiceClient adGroupAdServiceClient = await AdGroupAdServiceClient.CreateAsync();

            // Initialize request argument(s)
            string customerId = "";
            IEnumerable <AdGroupAdOperation> operations = new AdGroupAdOperation[]
            {
                new AdGroupAdOperation(),
            };
            // Make the request
            MutateAdGroupAdsResponse response = await adGroupAdServiceClient.MutateAdGroupAdsAsync(customerId, operations);

            // End snippet
        }
 /// <summary>Snippet for MutateAdGroupAds</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void MutateAdGroupAdsRequestObject()
 {
     // Create client
     AdGroupAdServiceClient adGroupAdServiceClient = AdGroupAdServiceClient.Create();
     // Initialize request argument(s)
     MutateAdGroupAdsRequest request = new MutateAdGroupAdsRequest
     {
         CustomerId = "",
         Operations =
         {
             new AdGroupAdOperation(),
         },
         PartialFailure = false,
         ValidateOnly   = false,
     };
     // Make the request
     MutateAdGroupAdsResponse response = adGroupAdServiceClient.MutateAdGroupAds(request);
 }
Exemplo n.º 22
0
        /// <summary>Snippet for MutateAdGroupAdsAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task MutateAdGroupAdsRequestObjectAsync()
        {
            // Create client
            AdGroupAdServiceClient adGroupAdServiceClient = await AdGroupAdServiceClient.CreateAsync();

            // Initialize request argument(s)
            MutateAdGroupAdsRequest request = new MutateAdGroupAdsRequest
            {
                CustomerId = "",
                Operations =
                {
                    new AdGroupAdOperation(),
                },
                PartialFailure      = false,
                ValidateOnly        = false,
                ResponseContentType = ResponseContentTypeEnum.Types.ResponseContentType.Unspecified,
            };
            // Make the request
            MutateAdGroupAdsResponse response = await adGroupAdServiceClient.MutateAdGroupAdsAsync(request);
        }
        // [END add_shopping_product_ad_1]

        /// <summary>
        /// Creates a new Shopping product ad group ad in the specified ad group.
        /// </summary>
        /// <param name="client">The Google Ads API client.</param>
        /// <param name="customerId">The client customer ID.</param>
        /// <param name="adGroupResourceName">The resource name of the ad group that the new ad
        /// group ad will belong to.</param>
        /// <returns>Resource name of the newly created ad group ad.</returns>
        /// <exception cref="GoogleAdsException">Thrown if an API request failed with one or more
        /// service errors.</exception>
        // [START add_shopping_product_ad]
        private string AddProductShoppingAdGroupAd(GoogleAdsClient client, long customerId,
                                                   string adGroupResourceName)
        {
            // Get the AdGroupAdService.
            AdGroupAdServiceClient adGroupAdService = client.GetService(
                Services.V10.AdGroupAdService);

            // Creates a new shopping product ad.
            Ad ad = new Ad()
            {
                ShoppingProductAd = new ShoppingProductAdInfo()
                {
                }
            };

            // Creates a new ad group ad and sets the shopping product ad to it.
            AdGroupAd adGroupAd = new AdGroupAd()
            {
                // Sets the ad to the ad created above.
                Ad = ad,

                Status = AdGroupAdStatus.Paused,

                // Sets the ad group.
                AdGroup = adGroupResourceName
            };

            // Creates an ad group ad operation.
            AdGroupAdOperation operation = new AdGroupAdOperation()
            {
                Create = adGroupAd
            };

            // Issues a mutate request to add an ad group ad.
            MutateAdGroupAdResult mutateAdGroupAdResult = adGroupAdService.MutateAdGroupAds(
                customerId.ToString(), new AdGroupAdOperation[] { operation }).Results[0];

            Console.WriteLine("Added a product shopping ad group ad with resource name: '{0}'.",
                              mutateAdGroupAdResult.ResourceName);
            return(mutateAdGroupAdResult.ResourceName);
        }
 /// <summary>Snippet for MutateAdGroupAds</summary>
 public void MutateAdGroupAdsRequestObject()
 {
     // Snippet: MutateAdGroupAds(MutateAdGroupAdsRequest, CallSettings)
     // Create client
     AdGroupAdServiceClient adGroupAdServiceClient = AdGroupAdServiceClient.Create();
     // Initialize request argument(s)
     MutateAdGroupAdsRequest request = new MutateAdGroupAdsRequest
     {
         CustomerId = "",
         Operations =
         {
             new AdGroupAdOperation(),
         },
         PartialFailure      = false,
         ValidateOnly        = false,
         ResponseContentType = ResponseContentTypeEnum.Types.ResponseContentType.Unspecified,
     };
     // Make the request
     MutateAdGroupAdsResponse response = adGroupAdServiceClient.MutateAdGroupAds(request);
     // End snippet
 }
        /// <summary>Snippet for MutateAdGroupAdsAsync</summary>
        public async Task MutateAdGroupAdsRequestObjectAsync()
        {
            // Snippet: MutateAdGroupAdsAsync(MutateAdGroupAdsRequest, CallSettings)
            // Additional: MutateAdGroupAdsAsync(MutateAdGroupAdsRequest, CancellationToken)
            // Create client
            AdGroupAdServiceClient adGroupAdServiceClient = await AdGroupAdServiceClient.CreateAsync();

            // Initialize request argument(s)
            MutateAdGroupAdsRequest request = new MutateAdGroupAdsRequest
            {
                CustomerId = "",
                Operations =
                {
                    new AdGroupAdOperation(),
                },
                PartialFailure = false,
                ValidateOnly   = false,
            };
            // Make the request
            MutateAdGroupAdsResponse response = await adGroupAdServiceClient.MutateAdGroupAdsAsync(request);

            // End snippet
        }
Exemplo n.º 26
0
        /// <summary>
        /// Creates a new hotel ad group ad in the specified ad group.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="adGroupResourceName">The resource name of ad group that a new ad group
        /// ad will belong to</param>
        private static void AddHotelAdGroupAd(GoogleAdsClient client, long customerId,
                                              string adGroupResourceName)
        {
            // Get the AdGroupAdService.
            AdGroupAdServiceClient service = client.GetService(Services.V4.AdGroupAdService);

            // Create a new ad group ad and sets the hotel ad to it.
            AdGroupAd adGroupAd = new AdGroupAd()
            {
                // Create a new hotel ad.
                Ad = new Ad()
                {
                    HotelAd = new HotelAdInfo(),
                },
                // Set the ad group.
                AdGroup = adGroupResourceName,
                // Set the ad group ad to enabled.  Setting this to paused will cause an error
                // for hotel campaigns.  For hotels pausing should happen at either the ad group or
                // campaign level.
                Status = AdGroupAdStatus.Enabled
            };

            // Create an ad group ad operation.
            AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation()
            {
                Create = adGroupAd
            };

            // Issue a mutate request to add an ad group ad.
            MutateAdGroupAdsResponse response = service.MutateAdGroupAds(customerId.ToString(),
                                                                         new AdGroupAdOperation[] { adGroupAdOperation });

            MutateAdGroupAdResult addedAdGroupAd = response.Results[0];

            Console.WriteLine($"Added a hotel ad group ad with resource name " +
                              $"{addedAdGroupAd.ResourceName}.");
        }
        /// <summary>Adds an expanded dynamic search ad.</summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="adGroupResourceName">The ad group resource name.</param>
        private static void AddExpandedDSA(GoogleAdsClient client, long customerId,
                                           string adGroupResourceName)
        {
            // Get the AdGroupAdService.
            AdGroupAdServiceClient adGroupAdService =
                client.GetService(Services.V4.AdGroupAdService);

            // Create an ad group ad.
            AdGroupAd adGroupAd = new AdGroupAd()
            {
                AdGroup = adGroupResourceName,
                Status  = AdGroupAdStatus.Paused,

                // Set the ad as an expanded dynamic search ad.
                Ad = new Ad()
                {
                    ExpandedDynamicSearchAd = new ExpandedDynamicSearchAdInfo()
                    {
                        Description = "Buy tickets now!"
                    }
                }
            };

            // Create the operation.
            AdGroupAdOperation operation = new AdGroupAdOperation()
            {
                Create = adGroupAd
            };

            // Add the dynamic search ad.
            MutateAdGroupAdsResponse response = adGroupAdService.MutateAdGroupAds(
                customerId.ToString(), new AdGroupAdOperation[] { operation });

            // Display the response.
            Console.WriteLine($"Added ad group ad with resource name " +
                              $"'{response.Results[0].ResourceName}'.");
        }
Exemplo n.º 28
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="adGroupId">ID of the ad group to which ads are added.</param>
        public void Run(GoogleAdsClient client, long customerId, long adGroupId)
        {
            // Get the AdGroupAdService.
            AdGroupAdServiceClient adGroupAdService = client.GetService(
                Services.V10.AdGroupAdService);

            // Create the ad group ad object.
            AdGroupAd adGroupAd = new AdGroupAd
            {
                AdGroup = ResourceNames.AdGroup(customerId, adGroupId),
                // Optional: Set the status.
                Status = AdGroupAdStatus.Paused,
                Ad     = new Ad
                {
                    ExpandedTextAd = new ExpandedTextAdInfo
                    {
                        Description   = "Luxury Cruise to Mars",
                        HeadlinePart1 = "Visit the Red Planet in style.",
                        HeadlinePart2 = "Low-gravity fun for everyone!!",
                    },
                    FinalUrls = { "http://www.example.com/" },
                }
            };

            // Create the operation.
            AdGroupAdOperation operation = new AdGroupAdOperation
            {
                Create = adGroupAd
            };

            try
            {
                // Create the ads, while setting validateOnly = true.
                MutateAdGroupAdsResponse response = adGroupAdService.MutateAdGroupAds(
                    new MutateAdGroupAdsRequest()
                {
                    CustomerId     = customerId.ToString(),
                    Operations     = { operation },
                    PartialFailure = false,
                    ValidateOnly   = true
                });

                // Since validation is ON, result will be null.
                Console.WriteLine("Expanded text ad validated successfully.");
            }
            catch (GoogleAdsException e)
            {
                // This block will be hit if there is a validation error from the server.
                Console.WriteLine(
                    "There were validation error(s) while adding expanded text ad.");

                if (e.Failure != null)
                {
                    // Note: Policy violation errors are returned as PolicyFindingErrors. See
                    // https://developers.google.com/google-ads/api/docs/policy-exemption/overview
                    // for additional details.
                    e.Failure.Errors
                    .Where(err =>
                           err.ErrorCode.PolicyFindingError == PolicyFindingError.PolicyFinding)
                    .ToList()
                    .ForEach(delegate(GoogleAdsError err)
                    {
                        int count = 1;
                        if (err.Details.PolicyFindingDetails != null)
                        {
                            foreach (PolicyTopicEntry entry in
                                     err.Details.PolicyFindingDetails.PolicyTopicEntries)
                            {
                                Console.WriteLine($"{count}) Policy topic entry with topic = " +
                                                  $"\"{entry.Topic}\" and type = \"{entry.Type}\" " +
                                                  $"was found.");
                            }
                        }
                        count++;
                    });
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Creates the responsive display ad.
        /// </summary>
        /// <param name="client">The Google Ads API client.</param>
        /// <param name="customerId">The client customer ID.</param>
        /// <param name="adGroupResourceName">The ad group resource name to receive the ad.</param>
        private void CreateAd(GoogleAdsClient client, long customerId, string adGroupResourceName)
        {
            // Creates the ad group ad service client.
            AdGroupAdServiceClient adGroupAdServiceClient =
                client.GetService(Services.V6.AdGroupAdService);

            string marketingImageUrl          = "https://goo.gl/3b9Wfh";
            string marketingImageName         = "Marketing Image";
            string marketingImageResourceName =
                uploadAsset(client, customerId, marketingImageUrl, marketingImageName);
            string squareMarketingImageName         = "Square Marketing Image";
            string squareMarketingImageUrl          = "https://goo.gl/mtt54n";
            string squareMarketingImageResourceName =
                uploadAsset(client, customerId, squareMarketingImageUrl, squareMarketingImageName);

            // Creates the responsive display ad info object.
            ResponsiveDisplayAdInfo responsiveDisplayAdInfo = new ResponsiveDisplayAdInfo()
            {
                MarketingImages =
                {
                    new AdImageAsset()
                    {
                        Asset = marketingImageResourceName
                    }
                },
                SquareMarketingImages =
                {
                    new AdImageAsset()
                    {
                        Asset = squareMarketingImageResourceName
                    }
                },
                Headlines =
                {
                    new AdTextAsset()
                    {
                        Text = "Travel"
                    }
                },
                LongHeadline = new AdTextAsset()
                {
                    Text = "Travel the World"
                },
                Descriptions =
                {
                    new AdTextAsset()
                    {
                        Text = "Take to the air!"
                    }
                },
                BusinessName = "Interplanetary Cruises",
                // Optional: Call to action text.
                // Valid texts: https://support.google.com/adwords/answer/7005917
                CallToActionText = "Apply Now",
                // Optional: Sets the ad colors.
                MainColor   = "#0000ff",
                AccentColor = "#ffff00",
                // Optional: Sets to false to strictly render the ad using the colors.
                AllowFlexibleColor = false,
                // Optional: Sets the format setting that the ad will be served in.
                FormatSetting = DisplayAdFormatSetting.NonNative,
                // Optional: Creates a logo image and sets it to the ad.

                /*
                 *  LogoImages = { new AdImageAsset()
                 *  {
                 *      Asset = "INSERT_LOGO_IMAGE_RESOURCE_NAME_HERE"
                 *  }}
                 */
                // Optional: Creates a square logo image and sets it to the ad.

                /*
                 *  SquareLogoImages = { new AdImageAsset()
                 *  {
                 *      Asset = "INSERT_SQUARE_LOGO_IMAGE_RESOURCE_NAME_HERE"
                 *  }}
                 */
            };

            // Creates the ad.
            Ad ad = new Ad()
            {
                ResponsiveDisplayAd = responsiveDisplayAdInfo,
                FinalUrls           = { "http://www.example.com/" }
            };

            // Creates the ad group ad.
            AdGroupAd adGroupAd = new AdGroupAd()
            {
                AdGroup = adGroupResourceName,
                Ad      = ad
            };

            // Creates the ad group ad operation.
            AdGroupAdOperation operation = new AdGroupAdOperation()
            {
                Create = adGroupAd
            };

            // Adds the ad group ad.
            MutateAdGroupAdsResponse response = adGroupAdServiceClient.MutateAdGroupAds
                                                    (customerId.ToString(), new[] { operation });

            Console.WriteLine("Created ad group ad with resource name " +
                              $"'{response.Results.First().ResourceName}'.");
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="adGroupId">ID of the ad group to which ads are added.</param>
        public void Run(GoogleAdsClient client, long customerId, long adGroupId)
        {
            // Get the AdGroupAdServiceClient.
            AdGroupAdServiceClient adGroupAdService = client.GetService(
                Services.V4.AdGroupAdService);

            string adGroupResourceName = ResourceNames.AdGroup(customerId, adGroupId);
            // Creates an expanded text ad info object.
            ExpandedTextAdInfo expandedTextAdInfo = new ExpandedTextAdInfo()
            {
                HeadlinePart1 = $"Cruise to Mars #{ExampleUtilities.GetShortRandomString()}",
                HeadlinePart2 = "Best Space Cruise Line",
                // Intentionally use an ad text that violates policy -- having too many exclamation
                // marks.
                Description = "Buy your tickets now!!!!!!!"
            };

            // Creates an ad group ad to hold the above ad.
            AdGroupAd adGroupAd = new AdGroupAd()
            {
                AdGroup = adGroupResourceName,
                // Set the ad group ad to PAUSED to prevent it from immediately serving.
                // Set to ENABLED once you've added targeting and the ad are ready to serve.
                Status = AdGroupAdStatus.Paused,
                // Sets the expanded text ad info on an Ad.
                Ad = new Ad()
                {
                    ExpandedTextAd = expandedTextAdInfo,
                    FinalUrls      = { "http://www.example.com" }
                }
            };

            // Creates an ad group ad operation.
            AdGroupAdOperation operation = new AdGroupAdOperation()
            {
                Create = adGroupAd
            };

            try
            {
                try
                {
                    // Try sending a mutate request to add the ad group ad.
                    adGroupAdService.MutateAdGroupAds(customerId.ToString(), new [] { operation });
                }
                catch (GoogleAdsException ex)
                {
                    // The request will always fail because of the policy violation in the
                    // description of the ad.
                    var ignorablePolicyTopics = FetchIgnorablePolicyTopics(ex);
                    // Try sending exemption requests for creating an expanded text ad.
                    RequestExemption(customerId, adGroupAdService, operation, ignorablePolicyTopics);
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }