示例#1
0
        /// <summary>
        /// Creates the keywords.
        /// </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 in which ads are created.</param>
        /// <param name="keywords">The keywords to create.</param>
        /// <returns>The list of newly created ad group criteria.</returns>
        private static gagvr::AdGroupCriterion[] CreateKeywords(GoogleAdsClient client,
                                                                long customerId, long adGroupId, string[] keywords)
        {
            // Get the AdGroupCriterionService.
            gagvs::AdGroupCriterionServiceClient adGroupCriterionService =
                client.GetService(Services.V6.AdGroupCriterionService);

            List <gagvs::AdGroupCriterionOperation> operations =
                new List <gagvs::AdGroupCriterionOperation>();

            foreach (string keywordText in keywords)
            {
                // Create a keyword.
                gagvr::AdGroupCriterion criterion = new gagvr::AdGroupCriterion()
                {
                    AdGroup = gagver::ResourceNames.AdGroup(customerId, adGroupId),
                    Status  = gag__AdGroupCriterionStatus.Enabled,
                    Keyword = new gagvc::KeywordInfo()
                    {
                        Text      = keywordText,
                        MatchType = gag__KeywordMatchType.Exact
                    }
                };

                // Create the operation.
                gagvs::AdGroupCriterionOperation operation = new gagvs::AdGroupCriterionOperation()
                {
                    Create = criterion,
                };
                operations.Add(operation);
            }

            // Add the keywords.
            gagvs::MutateAdGroupCriteriaResponse response =
                adGroupCriterionService.MutateAdGroupCriteria(customerId.ToString(),
                                                              operations);

            // Retrieve the newly created keywords.
            List <string> newResourceNames =
                response.Results.Select(result => result.ResourceName).ToList();

            gagvr::AdGroupCriterion[] newCriteria = GetKeywords(client, customerId,
                                                                newResourceNames);

            // Display the results.
            foreach (gagvr::AdGroupCriterion newCriterion in newCriteria)
            {
                Console.WriteLine("Keyword with text '{0}', id = '{1}' and match type = " +
                                  "'{2}' was retrieved for ad group '{3}'.",
                                  newCriterion.Keyword.Text,
                                  newCriterion.CriterionId,
                                  newCriterion.Keyword.MatchType,
                                  newCriterion.AdGroup);
            }

            // Return the newly created ad group criteria.
            return(newCriteria);
        }
示例#2
0
        public async stt::Task GetAdGroupCriterionResourceNamesAsync()
        {
            moq::Mock <AdGroupCriterionService.AdGroupCriterionServiceClient> mockGrpcClient = new moq::Mock <AdGroupCriterionService.AdGroupCriterionServiceClient>(moq::MockBehavior.Strict);
            GetAdGroupCriterionRequest request = new GetAdGroupCriterionRequest
            {
                ResourceNameAsAdGroupCriterionName = gagvr::AdGroupCriterionName.FromCustomerAdGroupCriterion("[CUSTOMER_ID]", "[AD_GROUP_ID]", "[CRITERION_ID]"),
            };
            gagvr::AdGroupCriterion expectedResponse = new gagvr::AdGroupCriterion
            {
                ResourceNameAsAdGroupCriterionName = gagvr::AdGroupCriterionName.FromCustomerAdGroupCriterion("[CUSTOMER_ID]", "[AD_GROUP_ID]", "[CRITERION_ID]"),
                Status              = gagve::AdGroupCriterionStatusEnum.Types.AdGroupCriterionStatus.Removed,
                QualityInfo         = new gagvr::AdGroupCriterion.Types.QualityInfo(),
                PositionEstimates   = new gagvr::AdGroupCriterion.Types.PositionEstimates(),
                UrlCustomParameters =
                {
                    new gagvc::CustomParameter(),
                },
                EffectiveCpcBidSource = gagve::BiddingSourceEnum.Types.BiddingSource.AdGroup,
                EffectiveCpmBidSource = gagve::BiddingSourceEnum.Types.BiddingSource.AdGroupCriterion,
                EffectiveCpvBidSource = gagve::BiddingSourceEnum.Types.BiddingSource.Unspecified,
                Type                         = gagve::CriterionTypeEnum.Types.CriterionType.MobileApplication,
                Keyword                      = new gagvc::KeywordInfo(),
                Placement                    = new gagvc::PlacementInfo(),
                MobileAppCategory            = new gagvc::MobileAppCategoryInfo(),
                MobileApplication            = new gagvc::MobileApplicationInfo(),
                ListingGroup                 = new gagvc::ListingGroupInfo(),
                EffectivePercentCpcBidSource = gagve::BiddingSourceEnum.Types.BiddingSource.AdGroup,
                AgeRange                     = new gagvc::AgeRangeInfo(),
                Gender                       = new gagvc::GenderInfo(),
                IncomeRange                  = new gagvc::IncomeRangeInfo(),
                ParentalStatus               = new gagvc::ParentalStatusInfo(),
                YoutubeVideo                 = new gagvc::YouTubeVideoInfo(),
                YoutubeChannel               = new gagvc::YouTubeChannelInfo(),
                UserList                     = new gagvc::UserListInfo(),
                Topic                        = new gagvc::TopicInfo(),
                UserInterest                 = new gagvc::UserInterestInfo(),
                Webpage                      = new gagvc::WebpageInfo(),
                AppPaymentModel              = new gagvc::AppPaymentModelInfo(),
                CustomAffinity               = new gagvc::CustomAffinityInfo(),
                CustomIntent                 = new gagvc::CustomIntentInfo(),
                SystemServingStatus          = gagve::CriterionSystemServingStatusEnum.Types.CriterionSystemServingStatus.Unknown,
                ApprovalStatus               = gagve::AdGroupCriterionApprovalStatusEnum.Types.AdGroupCriterionApprovalStatus.Approved,
                CriterionId                  = 8584655242409302840L,
                AdGroupAsAdGroupName         = gagvr::AdGroupName.FromCustomerAdGroup("[CUSTOMER_ID]", "[AD_GROUP_ID]"),
                Negative                     = false,
                DisapprovalReasons           =
                {
                    "disapproval_reasons9e26b1a0",
                },
                BidModifier                  = 1.6595195068951933E+17,
                CpcBidMicros                 = 7321761304249472746L,
                CpmBidMicros                 = -6938481569984464040L,
                CpvBidMicros                 = 3393527949878021854L,
                PercentCpcBidMicros          = 3342096754779167220L,
                EffectiveCpcBidMicros        = -8231435192357073166L,
                EffectiveCpmBidMicros        = -8933191455000353270L,
                EffectiveCpvBidMicros        = 3707485164400289602L,
                EffectivePercentCpcBidMicros = 8313662352690151473L,
                FinalUrls =
                {
                    "final_urls3ed0b71b",
                },
                FinalMobileUrls =
                {
                    "final_mobile_urlsf4131aa0",
                },
                FinalUrlSuffix      = "final_url_suffix046ed37a",
                TrackingUrlTemplate = "tracking_url_template157f152a",
                CustomAudience      = new gagvc::CustomAudienceInfo(),
                CombinedAudience    = new gagvc::CombinedAudienceInfo(),
            };

            mockGrpcClient.Setup(x => x.GetAdGroupCriterionAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <gagvr::AdGroupCriterion>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            AdGroupCriterionServiceClient client = new AdGroupCriterionServiceClientImpl(mockGrpcClient.Object, null);
            gagvr::AdGroupCriterion       responseCallSettings = await client.GetAdGroupCriterionAsync(request.ResourceNameAsAdGroupCriterionName, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            gagvr::AdGroupCriterion responseCancellationToken = await client.GetAdGroupCriterionAsync(request.ResourceNameAsAdGroupCriterionName, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }