示例#1
0
        // [END add_smart_campaign_1]

        // [START add_smart_campaign_10]
        /// <summary>
        /// Retrieves creative suggestions for a Smart campaign ad.
        ///
        /// Using the SmartCampaignSuggestService to suggest creatives for new
        /// and existing Smart campaigns is highly recommended because it helps
        /// the campaigns achieve optimal performance.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="customerId">The Google Ads customer ID.</param>
        /// <param name="suggestionInfo">a SmartCampaignSuggestionInfo instance
        /// with details about the business being advertised.</param>
        /// <returns>A SmartCampaignAdInfo instance with suggested headlines and
        /// descriptions.</returns>
        private SmartCampaignAdInfo GetAdSuggestions(GoogleAdsClient client,
                                                     long customerId, SmartCampaignSuggestionInfo suggestionInfo)
        {
            SmartCampaignSuggestServiceClient smartCampaignSuggestService =
                client.GetService(Services.V10.SmartCampaignSuggestService);

            SuggestSmartCampaignAdRequest request = new SuggestSmartCampaignAdRequest
            {
                CustomerId = customerId.ToString(),
                // Unlike the SuggestSmartCampaignBudgetOptions method, it's only possible to
                // use suggestion_info to retrieve ad creative suggestions.
                SuggestionInfo = suggestionInfo
            };

            // Issue a request to retrieve ad creative suggestions.
            SuggestSmartCampaignAdResponse response =
                smartCampaignSuggestService.SuggestSmartCampaignAd(request);

            // The SmartCampaignAdInfo object in the response contains a list of up to
            // three headlines and two descriptions. Note that some of the suggestions
            // may have empty strings as text. Before setting these on the ad you should
            // review them and filter out any empty values.
            SmartCampaignAdInfo adSuggestions = response.AdInfo;

            if (adSuggestions != null)
            {
                Console.WriteLine($"The following headlines were suggested:");
                foreach (AdTextAsset headline in adSuggestions.Headlines)
                {
                    Console.WriteLine($"\t{headline.Text}");
                }

                Console.WriteLine($"And the following descriptions were suggested:");
                foreach (AdTextAsset description in adSuggestions.Descriptions)
                {
                    Console.WriteLine($"\t{description.Text}");
                }
            }
            else
            {
                Console.WriteLine("No ad suggestions were found.");
                adSuggestions = new SmartCampaignAdInfo();
            }

            return(adSuggestions);
        }
示例#2
0
        public void SuggestSmartCampaignAdRequestObject()
        {
            moq::Mock <SmartCampaignSuggestService.SmartCampaignSuggestServiceClient> mockGrpcClient = new moq::Mock <SmartCampaignSuggestService.SmartCampaignSuggestServiceClient>(moq::MockBehavior.Strict);
            SuggestSmartCampaignAdRequest request = new SuggestSmartCampaignAdRequest
            {
                CustomerId     = "customer_id3b3724cb",
                SuggestionInfo = new SmartCampaignSuggestionInfo(),
            };
            SuggestSmartCampaignAdResponse expectedResponse = new SuggestSmartCampaignAdResponse
            {
                AdInfo = new gagvc::SmartCampaignAdInfo(),
            };

            mockGrpcClient.Setup(x => x.SuggestSmartCampaignAd(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            SmartCampaignSuggestServiceClient client   = new SmartCampaignSuggestServiceClientImpl(mockGrpcClient.Object, null);
            SuggestSmartCampaignAdResponse    response = client.SuggestSmartCampaignAd(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
示例#3
0
        public async stt::Task SuggestSmartCampaignAdRequestObjectAsync()
        {
            moq::Mock <SmartCampaignSuggestService.SmartCampaignSuggestServiceClient> mockGrpcClient = new moq::Mock <SmartCampaignSuggestService.SmartCampaignSuggestServiceClient>(moq::MockBehavior.Strict);
            SuggestSmartCampaignAdRequest request = new SuggestSmartCampaignAdRequest
            {
                CustomerId     = "customer_id3b3724cb",
                SuggestionInfo = new SmartCampaignSuggestionInfo(),
            };
            SuggestSmartCampaignAdResponse expectedResponse = new SuggestSmartCampaignAdResponse
            {
                AdInfo = new gagvc::SmartCampaignAdInfo(),
            };

            mockGrpcClient.Setup(x => x.SuggestSmartCampaignAdAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <SuggestSmartCampaignAdResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            SmartCampaignSuggestServiceClient client = new SmartCampaignSuggestServiceClientImpl(mockGrpcClient.Object, null);
            SuggestSmartCampaignAdResponse    responseCallSettings = await client.SuggestSmartCampaignAdAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            Assert.AreEqual(expectedResponse, responseCallSettings);
            SuggestSmartCampaignAdResponse responseCancellationToken = await client.SuggestSmartCampaignAdAsync(request, st::CancellationToken.None);

            Assert.AreEqual(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }