示例#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.V0.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}.");
        }
示例#2
0
        public void MutateAdGroupAds()
        {
            moq::Mock <AdGroupAdService.AdGroupAdServiceClient> mockGrpcClient = new moq::Mock <AdGroupAdService.AdGroupAdServiceClient>(moq::MockBehavior.Strict);
            MutateAdGroupAdsRequest request = new MutateAdGroupAdsRequest
            {
                CustomerId = "customer_id3b3724cb",
                Operations =
                {
                    new AdGroupAdOperation(),
                },
            };
            MutateAdGroupAdsResponse expectedResponse = new MutateAdGroupAdsResponse
            {
                Results =
                {
                    new MutateAdGroupAdResult(),
                },
                PartialFailureError = new gr::Status(),
            };

            mockGrpcClient.Setup(x => x.MutateAdGroupAds(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            AdGroupAdServiceClient   client   = new AdGroupAdServiceClientImpl(mockGrpcClient.Object, null);
            MutateAdGroupAdsResponse response = client.MutateAdGroupAds(request.CustomerId, request.Operations);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
示例#3
0
        public void MutateAdGroupAdsRequestObject()
        {
            moq::Mock <AdGroupAdService.AdGroupAdServiceClient> mockGrpcClient = new moq::Mock <AdGroupAdService.AdGroupAdServiceClient>(moq::MockBehavior.Strict);
            MutateAdGroupAdsRequest request = new MutateAdGroupAdsRequest
            {
                CustomerId = "customer_id3b3724cb",
                Operations =
                {
                    new AdGroupAdOperation(),
                },
                PartialFailure      = false,
                ValidateOnly        = true,
                ResponseContentType = gagve::ResponseContentTypeEnum.Types.ResponseContentType.ResourceNameOnly,
            };
            MutateAdGroupAdsResponse expectedResponse = new MutateAdGroupAdsResponse
            {
                Results =
                {
                    new MutateAdGroupAdResult(),
                },
                PartialFailureError = new gr::Status(),
            };

            mockGrpcClient.Setup(x => x.MutateAdGroupAds(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            AdGroupAdServiceClient   client   = new AdGroupAdServiceClientImpl(mockGrpcClient.Object, null);
            MutateAdGroupAdsResponse response = client.MutateAdGroupAds(request);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
示例#4
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.V4.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}");
                throw;
            }
        }
示例#5
0
        public async stt::Task MutateAdGroupAdsAsync()
        {
            moq::Mock <AdGroupAdService.AdGroupAdServiceClient> mockGrpcClient = new moq::Mock <AdGroupAdService.AdGroupAdServiceClient>(moq::MockBehavior.Strict);
            MutateAdGroupAdsRequest request = new MutateAdGroupAdsRequest
            {
                CustomerId = "customer_id3b3724cb",
                Operations =
                {
                    new AdGroupAdOperation(),
                },
            };
            MutateAdGroupAdsResponse expectedResponse = new MutateAdGroupAdsResponse
            {
                Results =
                {
                    new MutateAdGroupAdResult(),
                },
                PartialFailureError = new gr::Status(),
            };

            mockGrpcClient.Setup(x => x.MutateAdGroupAdsAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <MutateAdGroupAdsResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            AdGroupAdServiceClient   client = new AdGroupAdServiceClientImpl(mockGrpcClient.Object, null);
            MutateAdGroupAdsResponse responseCallSettings = await client.MutateAdGroupAdsAsync(request.CustomerId, request.Operations, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            Assert.AreEqual(expectedResponse, responseCallSettings);
            MutateAdGroupAdsResponse responseCancellationToken = await client.MutateAdGroupAdsAsync(request.CustomerId, request.Operations, st::CancellationToken.None);

            Assert.AreEqual(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
示例#6
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;
            }
        }
示例#7
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 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>
        /// 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}'.");
            }
        }
示例#10
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;
            }
        }
        /// <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.");
        }
示例#12
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);
 }
        public async Task MutateAdGroupAdsAsync2()
        {
            Mock <AdGroupAdService.AdGroupAdServiceClient> mockGrpcClient = new Mock <AdGroupAdService.AdGroupAdServiceClient>(MockBehavior.Strict);
            MutateAdGroupAdsRequest request = new MutateAdGroupAdsRequest
            {
                CustomerId = "customerId-1772061412",
                Operations = { },
            };
            MutateAdGroupAdsResponse expectedResponse = new MutateAdGroupAdsResponse();

            mockGrpcClient.Setup(x => x.MutateAdGroupAdsAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <MutateAdGroupAdsResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            AdGroupAdServiceClient   client   = new AdGroupAdServiceClientImpl(mockGrpcClient.Object, null);
            MutateAdGroupAdsResponse response = await client.MutateAdGroupAdsAsync(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        public void MutateAdGroupAds2()
        {
            Mock <AdGroupAdService.AdGroupAdServiceClient> mockGrpcClient = new Mock <AdGroupAdService.AdGroupAdServiceClient>(MockBehavior.Strict);
            MutateAdGroupAdsRequest request = new MutateAdGroupAdsRequest
            {
                CustomerId = "customerId-1772061412",
                Operations = { },
            };
            MutateAdGroupAdsResponse expectedResponse = new MutateAdGroupAdsResponse();

            mockGrpcClient.Setup(x => x.MutateAdGroupAds(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            AdGroupAdServiceClient   client   = new AdGroupAdServiceClientImpl(mockGrpcClient.Object, null);
            MutateAdGroupAdsResponse response = client.MutateAdGroupAds(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
示例#17
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);
        }
 /// <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
        }
示例#20
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}'.");
        }
        public async Task MutateAdGroupAdsAsync()
        {
            Mock <AdGroupAdService.AdGroupAdServiceClient> mockGrpcClient = new Mock <AdGroupAdService.AdGroupAdServiceClient>(MockBehavior.Strict);
            MutateAdGroupAdsRequest expectedRequest = new MutateAdGroupAdsRequest
            {
                CustomerId     = "customerId-1772061412",
                Operations     = { },
                PartialFailure = true,
                ValidateOnly   = false,
            };
            MutateAdGroupAdsResponse expectedResponse = new MutateAdGroupAdsResponse();

            mockGrpcClient.Setup(x => x.MutateAdGroupAdsAsync(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <MutateAdGroupAdsResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            AdGroupAdServiceClient client = new AdGroupAdServiceClientImpl(mockGrpcClient.Object, null);
            string customerId             = "customerId-1772061412";
            IEnumerable <AdGroupAdOperation> operations = new List <AdGroupAdOperation>();
            bool partialFailure = true;
            bool validateOnly   = false;
            MutateAdGroupAdsResponse response = await client.MutateAdGroupAdsAsync(customerId, operations, partialFailure, validateOnly);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        /// <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}");
            }
        }
示例#24
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}'.");
        }
示例#25
0
        /// <summary>
        /// Creates the responsive display 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>
        /// <param name="marketingImageAssetResourceName">The marketing image asset resource
        /// name.</param>
        /// <param name="squareMarketingImageAssetResourceName">The square marketing image asset
        /// resource name.</param>
        /// <returns>Resource name of the newly created ad.</returns>
        private static string CreateResponsiveDisplayAd(GoogleAdsClient client, long customerId,
                                                        string adGroupResourceName, string marketingImageAssetResourceName,
                                                        string squareMarketingImageAssetResourceName)
        {
            // Get the AdGroupAdServiceClient.
            AdGroupAdServiceClient adGroupAdService =
                client.GetService(Services.V3.AdGroupAdService);

            // Creates a responsive display ad info.
            ResponsiveDisplayAdInfo responsiveDisplayAdInfo = new ResponsiveDisplayAdInfo()
            {
                // Sets some basic required information for the responsive display ad.
                Headlines = { new AdTextAsset()
                              {
                                  Text = "Travel"
                              } },
                LongHeadline = new AdTextAsset()
                {
                    Text = "Travel the World"
                },
                Descriptions = { new AdTextAsset()
                                 {
                                     Text = "Take to the air!"
                                 } },
                BusinessName = "Google",

                // Sets the marketing image and square marketing image to the previously created
                // image assets.
                MarketingImages =
                {
                    new AdImageAsset()
                    {
                        Asset = marketingImageAssetResourceName
                    }
                },
                SquareMarketingImages =
                {
                    new AdImageAsset()
                    {
                        Asset = squareMarketingImageAssetResourceName
                    }
                },

                // Optional: Sets call to action text, price prefix and promotion text.
                CallToActionText = "Shop Now",
                PricePrefix      = "as low as",
                PromoText        = "Free shipping!"
            };

            // Creates an ad group ad with the created responsive display ad info.
            AdGroupAd adGroupAd = new AdGroupAd()
            {
                AdGroup = adGroupResourceName,
                Status  = AdGroupAdStatus.Paused,
                Ad      = new Ad()
                {
                    FinalUrls           = { "https://www.example.com" },
                    ResponsiveDisplayAd = responsiveDisplayAdInfo
                }
            };

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

            // Issues a mutate request to add the ad.
            MutateAdGroupAdsResponse response =
                adGroupAdService.MutateAdGroupAds(customerId.ToString(), new[] { operation });

            string adGroupAdResourceName = response.Results.First().ResourceName;

            // Print out some information about the added ad group ad.
            Console.WriteLine($"Added ad group ad with resource name = '{adGroupAdResourceName}'.");

            return(adGroupAdResourceName);
        }
        /// <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 to which ads are added.</param>
        public void Run(GoogleAdsClient client, long customerId, long adGroupId)
        {
            // Get the AdGroupAdService.
            AdGroupAdServiceClient service = client.GetService(Services.V4.AdGroupAdService);

            // Create the expanded text ad.
            AdGroupAd ad = new AdGroupAd
            {
                AdGroup = ResourceNames.AdGroup(customerId, adGroupId),
                Ad      = new Ad
                {
                    ExpandedTextAd = new ExpandedTextAdInfo
                    {
                        Description   = "Low-gravity fun for everyone!",
                        HeadlinePart1 = "Luxury Cruise to Mars",
                        HeadlinePart2 = "Visit the Red Planet in style.",
                    },

                    // Specify a tracking URL for 3rd party tracking provider. You may
                    // specify one at customer, campaign, ad group, ad, criterion or
                    // feed item levels.
                    TrackingUrlTemplate =
                        "http://tracker.example.com/?season={_season}&promocode={_promocode}&u={lpurl}",

                    // Since your tracking URL has two custom parameters, provide their
                    // values too. This can be provided at campaign, ad group, ad, criterion
                    // or feed item levels.
                    UrlCustomParameters =
                    {
                        new CustomParameter {
                            Key = "season", Value = "christmas"
                        },
                        new CustomParameter {
                            Key = "promocode", Value = "NY123"
                        }
                    },

                    // Specify a list of final URLs. This field cannot be set if URL field is
                    // set. This may be specified at ad, criterion and feed item levels.
                    FinalUrls =
                    {
                        "http://www.example.com/cruise/space/",
                        "http://www.example.com/locations/mars/"
                    },

                    // Specify a list of final mobile URLs. This field cannot be set if URL
                    // field is set, or finalUrls is unset. This may be specified at ad,
                    // criterion and feed item levels.
                    FinalMobileUrls =
                    {
                        "http://mobile.example.com/cruise/space/",
                        "http://mobile.example.com/locations/mars/"
                    }
                },
                // Optional: Set the status.
                Status = AdGroupAdStatus.Paused
            };

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

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

                // Display the results.
                foreach (MutateAdGroupAdResult result in response.Results)
                {
                    Console.WriteLine($"Expanded text ad created with resource name: " +
                                      $"{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;
            }
        }
        // [END add_responsive_search_ad_with_ad_customizer_2]

        // [START add_responsive_search_ad_with_ad_customizer_3]
        /// <summary>
        /// Creates a responsive search ad that uses the specified customizer attribute.
        /// </summary>
        /// <param name="client">The Google Ads API client.</param>
        /// <param name="customerId">The customer ID.</param>
        /// <param name="adGroupId">The ad group ID.</param>
        /// <param name="customizerAttributeName">The name of the customizer attribute.</param>
        private void CreateResponsiveSearchAdWithCustomization(
            GoogleAdsClient client,
            long customerId,
            long adGroupId,
            string customizerAttributeName)
        {
            // Creates an ad group ad operation.
            AdGroupAdOperation operation = new AdGroupAdOperation()
            {
                // Creates an ad group ad to hold the ad.
                Create = new AdGroupAd()
                {
                    AdGroup = ResourceNames.AdGroup(customerId, adGroupId),
                    Status  = AdGroupAdStatus.Paused,

                    // Creates an ad and sets responsive search ad info.
                    Ad = new Ad()
                    {
                        ResponsiveSearchAd = new ResponsiveSearchAdInfo()
                        {
                            Headlines =
                            {
                                // Sets a pinning to always choose this asset for HEADLINE_1. Pinning is
                                // optional; if no pinning is set, then headlines and descriptions will be
                                // rotated and the ones that perform best will be used more often.
                                new AdTextAsset()
                                {
                                    Text = "Cruise to Mars"
                                },
                                new AdTextAsset()
                                {
                                    Text = "Best Space Cruise Line"
                                },
                                new AdTextAsset()
                                {
                                    Text = "Experience the Stars"
                                }
                            },

                            Descriptions =
                            {
                                new AdTextAsset()
                                {
                                    Text = "Buy your tickets now"
                                },

                                // Creates this particular description using the ad customizer. For
                                // details about the placeholder format, visit the following:
                                // https://developers.google.com/google-ads/api/docs/ads/customize-responsive-search-ads#ad_customizers_in_responsive_search_ads
                                //
                                // The ad customizer replaces the placeholder with the value we
                                // previously created and linked to the customer using
                                // `CustomerCustomizer`.
                                new AdTextAsset()
                                {
                                    Text = $"Just {{CUSTOMIZER.{customizerAttributeName}:10USD}}"
                                }
                            },

                            Path1 = "all-inclusive",
                            Path2 = "deals"
                        },

                        FinalUrls = { "http://www.example.com" }
                    }
                }
            };

            // Issues a mutate request to add the ad group ad and prints its information.
            AdGroupAdServiceClient serviceClient = client.GetService(Services.V10.AdGroupAdService);

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

            string resourceName = response.Results[0].ResourceName;

            Console.WriteLine($"Created responsive search ad with resource name '{resourceName}'.");
        }
示例#28
0
        /// <summary>
        /// Creates an App ad for a given 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 the ad group to add the App
        /// ad to.</param>
        private void CreateAppAd(GoogleAdsClient client, long customerId,
                                 string adGroupResourceName)
        {
            // Get the AdGroupAdService.
            AdGroupAdServiceClient adGroupAdService = client.GetService(
                Services.V4.AdGroupAdService);

            // Creates an ad group ad.
            AdGroupAd adGroupAd = new AdGroupAd
            {
                AdGroup = adGroupResourceName,
                Status  = AdGroupAdStatus.Enabled,
                Ad      = new Ad
                {
                    AppAd = new AppAdInfo
                    {
                        Headlines =
                        {
                            new AdTextAsset()
                            {
                                Text = "A cool puzzle game"
                            },
                            new AdTextAsset()
                            {
                                Text = "Remove connected blocks"
                            },
                        },
                        Descriptions =
                        {
                            new AdTextAsset()
                            {
                                Text = "3 difficulty levels"
                            },
                            new AdTextAsset()
                            {
                                Text = "4 colorful fun skins"
                            }
                        },
                        // Optional: You can set up to 20 image assets for your campaign.
                        //Images =
                        //{
                        //    new AdImageAsset()
                        //    {
                        //        Asset = ResourceNames.Asset(customerId, assetId)
                        //    }
                        //}
                    }
                }
            };

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

            // Submits the ad group ad operation to add the ad group ad and prints the results.
            MutateAdGroupAdsResponse response =
                adGroupAdService.MutateAdGroupAds(customerId.ToString(), new[] { operation });

            Console.WriteLine($"Created an ad group ad with ad with resource name " +
                              $"'{response.Results[0].ResourceName}'.");
        }
        /// <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.V3.AdGroupAdService);

            // Create the ad.
            Ad ad = new Ad()
            {
                ResponsiveSearchAd = new ResponsiveSearchAdInfo()
                {
                    Headlines =
                    {
                        // Sets a pinning to always choose this asset for HEADLINE_1. Pinning is
                        // optional; if no pinning is set, then headlines and descriptions will be
                        // rotated and the ones that perform best will be used more often.
                        new AdTextAsset()
                        {
                            Text        = "Cruise to Mars #" + ExampleUtilities.GetRandomString(),
                            PinnedField = ServedAssetFieldType.Headline1
                        },
                        new AdTextAsset()
                        {
                            Text = "Best Space Cruise Line"
                        },
                        new AdTextAsset()
                        {
                            Text = "Experience the Stars"
                        },
                        new AdTextAsset()
                        {
                            Text = "Buy your tickets now"
                        },
                        new AdTextAsset()
                        {
                            Text = "Visit the Red Planet"
                        },
                    },
                    Path1 = "all-inclusive",
                    Path2 = "deals"
                },
                FinalUrls = { "http://www.example.com" }
            };

            // Builds the final ad group ad representation.
            AdGroupAd adGroupAd = new AdGroupAd()
            {
                AdGroup = ResourceNames.AdGroup(customerId, adGroupId),
                Status  = AdGroupAdStatusEnum.Types.AdGroupAdStatus.Paused,
                Ad      = ad
            };

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

            try
            {
                MutateAdGroupAdsResponse response =
                    adGroupAdService.MutateAdGroupAds(customerId.ToString(), new[] { operation });
                foreach (MutateAdGroupAdResult result in response.Results)
                {
                    Console.WriteLine($"Responsive search ad created with resource name:" +
                                      $" '{result.ResourceName}'.");
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
            }
        }
示例#30
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID.</param>
        /// <param name="adGroupId">The ad group ID.</param>
        /// <param name="phoneCountry">The phone number country.</param>
        /// <param name="phoneNumber">The phone number itself.</param>
        /// <param name="conversionActionId">The conversion action ID or null.</param>
        public void Run(
            GoogleAdsClient client,
            long customerId,
            long adGroupId,
            string phoneCountry,
            string phoneNumber,
            long?conversionActionId)
        {
            try
            {
                // Creates an ad group ad for the new ad.
                AdGroupAd adGroupAd = new AdGroupAd()
                {
                    AdGroup = ResourceNames.AdGroup(customerId, adGroupId),
                    Status  = AdGroupAdStatus.Paused,
                    Ad      = new Ad()
                    {
                        // The URL of the webpage to refer to.
                        FinalUrls = { "https://www.example.com" },
                        CallAd    = new CallAdInfo()
                        {
                            BusinessName = "Google",
                            Headline1    = "Travel",
                            Headline2    = "Discover",
                            Description1 = "Travel the World",
                            Description2 = "Travel the Universe",

                            // Sets the country code and phone number of the business to call.
                            CountryCode = phoneCountry,
                            PhoneNumber = phoneNumber,

                            // Sets the verification URL to a webpage that includes the phone
                            // number.
                            PhoneNumberVerificationUrl = "https://www.example.com/contact",

                            // The fields below are optional.

                            // Configures call tracking and reporting.
                            CallTracked           = true,
                            DisableCallConversion = false,

                            // Sets path parts to append for display.
                            Path1 = "services",
                            Path2 = "travels",
                        }
                    }
                };

                // Sets the conversion action ID to the one provided if any.
                if (conversionActionId.HasValue)
                {
                    adGroupAd.Ad.CallAd.ConversionAction =
                        ResourceNames.ConversionAction(customerId, conversionActionId.Value);

                    adGroupAd.Ad.CallAd.ConversionReportingState =
                        CallConversionReportingState.UseResourceLevelCallConversionAction;
                }

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

                // Issues a mutate request to add the ad group ad.
                AdGroupAdServiceClient adGroupAdServiceClient =
                    client.GetService(Services.V10.AdGroupAdService);

                MutateAdGroupAdsResponse adGroupAdResponse =
                    adGroupAdServiceClient.MutateAdGroupAds(
                        customerId.ToString(),
                        new[] { adGroupAdOperation }
                        );

                string adGroupAdResourceName = adGroupAdResponse.Results.First().ResourceName;

                Console.WriteLine(
                    $"Created ad group ad with resource name: '{adGroupAdResourceName}'."
                    );
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }