示例#1
0
        /// <summary>
        /// Creates the campaign draft.
        /// </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="baseCampaignId">The base campaign ID.</param>
        /// <returns></returns>
        private static string CreateCampaignDraft(GoogleAdsClient client, long customerId,
                                                  long baseCampaignId)
        {
            // Get the CampaignDraftService.
            CampaignDraftServiceClient campaignDraftService =
                client.GetService(Services.V2.CampaignDraftService);

            CampaignDraft campaignDraft = new CampaignDraft()
            {
                BaseCampaign = ResourceNames.Campaign(customerId, baseCampaignId),
                Name         = "Campaign Draft #" + ExampleUtilities.GetRandomString(),
            };

            CampaignDraftOperation operation = new CampaignDraftOperation()
            {
                Create = campaignDraft
            };

            MutateCampaignDraftsResponse response = campaignDraftService.MutateCampaignDrafts(
                customerId.ToString(), new CampaignDraftOperation[] { operation });

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

            Console.WriteLine($"Campaign with resource ID = '{draftResourceName}' was added.");
            return(draftResourceName);
        }
示例#2
0
        /// <summary>
        /// Builds new campaign operations for the specified customer ID.
        /// </summary>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="campaignBudgetResourceName">The resource name of campaign budget to be
        /// used to create campaigns.</param>
        /// <returns>The campaign operations.</returns>
        private static List <CampaignOperation> BuildCampaignOperations(long customerId,
                                                                        string campaignBudgetResourceName)
        {
            List <CampaignOperation> operations = new List <CampaignOperation>();

            for (int i = 0; i < NUMBER_OF_CAMPAIGNS_TO_ADD; i++)
            {
                // Creates a campaign.
                long     campaignId = GetNextTemporaryId();
                Campaign campaign   = new Campaign()
                {
                    ResourceName           = ResourceNames.Campaign(customerId, campaignId),
                    Name                   = "batch job campaign #" + ExampleUtilities.GetRandomString(),
                    AdvertisingChannelType = AdvertisingChannelType.Search,

                    // Recommendation: Set the campaign to PAUSED when creating it to prevent
                    // the ads from immediately serving. Set to ENABLED once you've added
                    // targeting and the ads are ready to serve.
                    Status = CampaignStatus.Paused,

                    // Sets the bidding strategy and budget.
                    ManualCpc      = new ManualCpc(),
                    CampaignBudget = campaignBudgetResourceName
                };

                // Creates a campaign operation and adds it to the operations list.
                CampaignOperation op = new CampaignOperation()
                {
                    Create = campaign
                };
                operations.Add(op);
            }

            return(operations);
        }
示例#3
0
        /// <summary>
        /// Adds a language criterion to the draft campaign.
        /// </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="draftCampaignResourceName">Resource name of the draft campaign.</param>
        private static void AddLanguageCriteria(GoogleAdsClient client, long customerId,
                                                string draftCampaignResourceName)
        {
            // Get the CampaignCriterionService.
            CampaignCriterionServiceClient campaignCriterionService =
                client.GetService(Services.V2.CampaignCriterionService);

            // Add a language criterion.
            CampaignCriterionOperation criterionOperation = new CampaignCriterionOperation()
            {
                Create = new CampaignCriterion()
                {
                    Language = new LanguageInfo()
                    {
                        // Spanish
                        LanguageConstant = ResourceNames.LanguageConstant(1003)
                    },
                    Campaign = draftCampaignResourceName
                }
            };

            MutateCampaignCriteriaResponse campaignCriteriaResponse =
                campaignCriterionService.MutateCampaignCriteria(
                    customerId.ToString(),
                    new CampaignCriterionOperation[] { criterionOperation });

            string newCampaignCriterionResource = campaignCriteriaResponse.Results[0].ResourceName;

            Console.WriteLine($"Campaign Criterion with resource ID = " +
                              $"'{newCampaignCriterionResource}' was added to campaign with resource ID = " +
                              $"'{draftCampaignResourceName}'.");
        }
示例#4
0
        /// <summary>
        /// Creates the lead form extension.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="campaignId">ID of the campaign to which lead form extensions are
        /// added.</param>
        /// <param name="leadFormAssetResourceName">The lead form asset resource name.</param>
        private void CreateLeadFormExtension(GoogleAdsClient client, long customerId,
                                             long campaignId, string leadFormAssetResourceName)
        {
            CampaignAssetServiceClient campaignAssetService = client.GetService(
                Services.V6.CampaignAssetService);

            // Creates the campaign asset for the lead form.
            CampaignAsset campaignAsset = new CampaignAsset()
            {
                Asset     = leadFormAssetResourceName,
                FieldType = AssetFieldTypeEnum.Types.AssetFieldType.LeadForm,
                Campaign  = ResourceNames.Campaign(customerId, campaignId),
            };

            CampaignAssetOperation operation = new CampaignAssetOperation()
            {
                Create = campaignAsset
            };

            MutateCampaignAssetsResponse response = campaignAssetService.MutateCampaignAssets(
                customerId.ToString(), new[] { operation });

            foreach (MutateCampaignAssetResult result in response.Results)
            {
                Console.WriteLine("Created campaign asset with resource name =" +
                                  $" '{result.ResourceName}' for campaign ID {campaignId}.");
            }
        }
示例#5
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="recommendationId">ID of the recommendation to dismiss.</param>
        public void Run(GoogleAdsClient client, long customerId, long recommendationId)
        {
            // Get the RecommendationServiceClient.
            RecommendationServiceClient service = client.GetService(
                Services.V10.RecommendationService);

            DismissRecommendationOperation operation = new DismissRecommendationOperation()
            {
                ResourceName = ResourceNames.Recommendation(customerId, recommendationId),
            };

            try
            {
                DismissRecommendationResponse response = service.DismissRecommendation(
                    customerId.ToString(), new DismissRecommendationOperation[] {
                    operation
                });
                foreach (DismissRecommendationResult result in response.Results)
                {
                    Console.WriteLine($"Dismissed recommendation 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;
            }
        }
示例#6
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="billingSetupId">ID of the billing setup to remove.</param>
        public void Run(GoogleAdsClient client, long customerId, long billingSetupId)
        {
            // Get the BillingSetupServiceClient.
            BillingSetupServiceClient billingSetupService = client.GetService(
                Services.V2.BillingSetupService);

            // Create the billing setup resource.
            String billingSetupResource = ResourceNames.BillingSetup(customerId, billingSetupId);

            // Construct an operation that will remove the billing setup.
            BillingSetupOperation operation = new BillingSetupOperation()
            {
                Remove = billingSetupResource
            };

            try
            {
                // Send the operation in a mutate request.
                MutateBillingSetupResponse response =
                    billingSetupService.MutateBillingSetup(customerId.ToString(), operation);

                Console.WriteLine("Removed billing setup with resource name '{0}'.",
                                  response.Result.ResourceName);
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
            }
        }
示例#7
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer account ID.</param>
        /// <param name="adGroupId">Id of the ad group that contains the keyword.</param>
        /// <param name="criterionId">Id of the keyword to be removed.</param>
        public void Run(GoogleAdsClient client, long customerId, long adGroupId, long criterionId)
        {
            // Get the AdGroupCriterionService.
            AdGroupCriterionServiceClient adGroupCriterionService = client.GetService(
                Services.V6.AdGroupCriterionService);

            // Create the operation.
            AdGroupCriterionOperation operation = new AdGroupCriterionOperation();

            operation.Remove = ResourceNames.AdGroupCriterion(customerId, adGroupId, criterionId);

            try
            {
                // Remove the keyword.
                MutateAdGroupCriteriaResponse retVal =
                    adGroupCriterionService.MutateAdGroupCriteria(customerId.ToString(),
                                                                  new AdGroupCriterionOperation[] { operation });

                // Display the results.
                MutateAdGroupCriterionResult removedKeyword = retVal.Results[0];
                Console.WriteLine($"Keyword with resource name = " +
                                  $"'{removedKeyword.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;
            }
        }
        /// <summary>
        /// Restricts the feed items to work only with a specific ad group; this prevents the
        /// feed items from being used elsewhere and makes sure they are used only for
        /// customizing a specific 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="adGroupIds">The ad group IDs to bind the feed items to..</param>
        /// <param name="feedItemResourceNames">The resource names of the feed items.</param>
        private void CreateFeedItemTargets(GoogleAdsClient client,
                                           long customerId, long[] adGroupIds, List <string> feedItemResourceNames)
        {
            // Get the FeedItemTargetServiceClient.
            FeedItemTargetServiceClient feedItemTargetService =
                client.GetService(Services.V5.FeedItemTargetService);

            // Bind each feed item to a specific ad group to make sure it will only be used to
            // customize ads inside that ad group; using the feed item elsewhere will result
            // in an error.
            for (int i = 0; i < feedItemResourceNames.Count; i++)
            {
                string feedItemResourceName = feedItemResourceNames[i];
                long   adGroupId            = adGroupIds[i];

                FeedItemTarget feedItemTarget = new FeedItemTarget()
                {
                    AdGroup  = ResourceNames.AdGroup(customerId, adGroupId),
                    FeedItem = feedItemResourceName
                };

                FeedItemTargetOperation feedItemTargetOperation = new FeedItemTargetOperation()
                {
                    Create = feedItemTarget
                };

                MutateFeedItemTargetsResponse response =
                    feedItemTargetService.MutateFeedItemTargets(customerId.ToString(),
                                                                new[] { feedItemTargetOperation });

                string feedItemTargetResourceName = response.Results[0].ResourceName;
                Console.WriteLine($"Added feed item target with resource name " +
                                  $"'{response.Results[0].ResourceName}'.");
            }
        }
示例#9
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.V0.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}");
            }
        }
示例#10
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 remove.</param>
        public void Run(GoogleAdsClient client, long customerId, long adGroupId)
        {
            // Get the AdGroupService.
            AdGroupServiceClient service = client.GetService(Services.V1.AdGroupService);

            // Construct an operation that will remove the ad group with the specified
            // resource name.
            AdGroupOperation operation = new AdGroupOperation
            {
                Remove = ResourceNames.AdGroup(customerId, adGroupId)
            };

            try
            {
                // Send the operation in a mutate request.
                MutateAdGroupsResponse response = service.MutateAdGroups(customerId.ToString(),
                                                                         new AdGroupOperation[] { operation });

                // Display the result.
                foreach (MutateAdGroupResult result in response.Results)
                {
                    Console.WriteLine($"Removed ad group with resourceName: " +
                                      $"{result.ResourceName}.");
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
            }
        }
        /// <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="conversionActionIds">The IDs of the conversion actions for the basic user
        /// list.</param>
        // [START add_conversion_based_user_list]
        public void Run(GoogleAdsClient client, long customerId, long[] conversionActionIds)
        {
            // Creates the service client.
            UserListServiceClient userListServiceClient =
                client.GetService(Services.V10.UserListService);

            List <UserListActionInfo> userListActionInfoList = new List <UserListActionInfo>();

            foreach (long conversionActionId in conversionActionIds)
            {
                // Creates the UserListActionInfo object for a given conversion action. This
                // specifies the conversion action that, when triggered, will cause a user to be
                // added to a UserList.
                userListActionInfoList.Add(new UserListActionInfo
                {
                    ConversionAction =
                        ResourceNames.ConversionAction(customerId, conversionActionId)
                });
            }

            // Creates a basic user list info object with all of the conversion actions.
            BasicUserListInfo basicUserListInfo = new BasicUserListInfo();

            basicUserListInfo.Actions.Add(userListActionInfoList);

            // Creates the basic user list.
            UserList basicUserList = new UserList
            {
                Name               = $"Example BasicUserList #{ExampleUtilities.GetShortRandomString()}",
                Description        = "A list of people who have triggered one or more conversion actions",
                MembershipLifeSpan = 365L,
                BasicUserList      = basicUserListInfo,
                MembershipStatus   = UserListMembershipStatus.Open
            };

            // Creates the operation.
            UserListOperation operation = new UserListOperation
            {
                Create = basicUserList
            };

            try
            {
                // Adds the new user list.
                MutateUserListsResponse response = userListServiceClient.MutateUserLists
                                                       (customerId.ToString(), new[] { operation });

                // Prints the result.
                Console.WriteLine("Created basic user list with resource name: " +
                                  $"{response.Results.First().ResourceName}");
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
            public string Next()
            {
                long i = next;

                Interlocked.Decrement(ref next);
                return(ResourceNames.Asset(customerId, i));
            }
示例#13
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="campaignExperimentId">ID of the campaign experiment to graduate.</param>
        public void Run(GoogleAdsClient client, long customerId, long campaignExperimentId)
        {
            // Get the CampaignExperimentService.
            CampaignExperimentServiceClient campaignExperimentService = client.GetService(
                Services.V3.CampaignExperimentService);

            try
            {
                // Graduating a campaign experiment requires a new budget. Since the budget for
                // the base campaign has explicitly_shared set to false, the budget cannot
                // be shared with the campaign after it is made independent by graduation.
                string budgetResourceName = CreateBudget(client, customerId);

                // Prints out some information about the created campaign budget.
                Console.WriteLine($"Created new budget with resource name '{budgetResourceName}' " +
                                  $"for adding to the experiment campaign during graduation.");

                // Graduates the experiment campaign using the campaign budget created above.
                GraduateCampaignExperimentResponse response =
                    campaignExperimentService.GraduateCampaignExperiment(
                        ResourceNames.CampaignExperiment(customerId, campaignExperimentId),
                        budgetResourceName);
                Console.WriteLine($"Campaign with resource name '{response.GraduatedCampaign}' " +
                                  $"is now graduated.");
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
示例#14
0
        /// <summary>
        ///  Adds campaigns to a CampaignGroup in the specified client account.
        /// </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="campaignGroupResourceName">The resource name of the campaign
        /// group.</param>
        /// <param name="campaignIds">The IDs of the campaigns to add to the campaign
        /// group.</param>
        private static void AddCampaignsToGroup(GoogleAdsClient client, long customerId,
                                                String campaignGroupResourceName, long[] campaignIds)
        {
            CampaignServiceClient campaignServiceClient = client.GetService(
                Services.V0.CampaignService);
            List <CampaignOperation> operations = new List <CampaignOperation>();

            foreach (long campaignId in campaignIds)
            {
                Campaign campaign = new Campaign()
                {
                    ResourceName  = ResourceNames.Campaign(customerId, campaignId),
                    CampaignGroup = campaignGroupResourceName
                };

                CampaignOperation op = new CampaignOperation()
                {
                    Update     = campaign,
                    UpdateMask = FieldMasks.AllSetFieldsOf(campaign)
                };
                operations.Add(op);
            }

            MutateCampaignsResponse response =
                campaignServiceClient.MutateCampaigns(customerId.ToString(), operations);

            Console.WriteLine($"Added {response.Results.Count} campaigns to campaign group " +
                              $"with resource name {campaignGroupResourceName}:");
            foreach (MutateCampaignResult campaignResponse in response.Results)
            {
                Console.WriteLine($"\t{campaignResponse.ResourceName}");
            }
        }
示例#15
0
        /// <summary>
        /// Updates the given TargetingSetting of an ad group.
        /// </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 for which to update the audience targeting
        ///     restriction.</param>
        /// <param name="targetingSetting">The updated targeting setting.</param>
        private void UpdateTargetingSetting(GoogleAdsClient client, long customerId, long
                                            adGroupId, TargetingSetting targetingSetting)
        {
            // Get the AdGroupService client.
            AdGroupServiceClient adGroupServiceClient =
                client.GetService(Services.V6.AdGroupService);

            // Create an ad group object with the updated targeting setting.
            AdGroup adGroup = new AdGroup
            {
                ResourceName     = ResourceNames.AdGroup(customerId, adGroupId),
                TargetingSetting = targetingSetting
            };

            // Construct an operation that will update the ad group, using the FieldMasks utility
            // to derive the update mask. This mask tells the Google Ads API which attributes of the
            // ad group you want to change.
            AdGroupOperation operation = new AdGroupOperation
            {
                Update     = adGroup,
                UpdateMask = FieldMasks.AllSetFieldsOf(adGroup)
            };

            // Send the operation in a mutate request.
            MutateAdGroupsResponse response =
                adGroupServiceClient.MutateAdGroups(customerId.ToString(), new[] { operation });

            // Print the resource name of the updated object.
            Console.WriteLine("Updated targeting setting of ad group with resource name " +
                              $"'{response.Results.First().ResourceName}'; set the AUDIENCE target restriction " +
                              "to 'Observation'.");
        }
示例#16
0
        /// <summary>
        /// Creates a new criterion containing a biddable unit listing group node.
        /// </summary>
        /// <param name="customerId">The client customer ID.</param>
        /// <param name="adGroupId">The ID of the ad group.</param>
        /// <param name="parentAdGroupCriterionResourceName">The resource name of the parent of
        /// this criterion.</param>
        /// <param name="listingDimensionInfo">The ListingDimensionInfo to be set for this listing
        /// group.</param>
        /// <param name="cpcBidMicros">The CPC bid for items in this listing group. This value
        /// should be specified in micros.</param>
        /// <returns>The ad group criterion object that contains the biddable unit listing group
        /// node.</returns>
        private AdGroupCriterion CreateListingGroupUnitBiddable(long customerId, long adGroupId,
                                                                String parentAdGroupCriterionResourceName, ListingDimensionInfo listingDimensionInfo,
                                                                long cpcBidMicros)
        {
            String           adGroupResourceName = ResourceNames.AdGroup(customerId, adGroupId);
            AdGroupCriterion adGroupCriterion    = new AdGroupCriterion()
            {
                // The resource name the ad group the listing group node will be attached to unit.
                // Note: Listing group units do not require temporary IDs if ad group resource name
                // and parentAdGroupCriterionResourceName are specified. To use temporary IDs for
                // unit criteria, use ResourceName property.
                AdGroup      = adGroupResourceName,
                Status       = AdGroupCriterionStatus.Enabled,
                ListingGroup = new ListingGroupInfo()
                {
                    // Set the type as a UNIT, which will allow the group to be biddable
                    Type = ListingGroupType.Unit,

                    // Set the ad group criterion resource name for the parent listing group.
                    // This can include a criterion ID if the parent criterion is not yet created.
                    // Use StringValue to convert from a String to a compatible argument type.
                    ParentAdGroupCriterion = parentAdGroupCriterionResourceName,

                    // Case values contain the listing dimension used for the node.
                    CaseValue = listingDimensionInfo
                },

                // Set the bid for this listing group unit.
                // This will be used as the CPC bid for items that are included in this
                // listing group
                CpcBidMicros = cpcBidMicros
            };

            return(adGroupCriterion);
        }
示例#17
0
        /// <summary>
        /// Retrieves the manager link resource name of a customer client link given its resource
        /// name.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="managerCustomerId">The manager customer ID.</param>
        /// <param name="clientCustomerId">The client customer ID.</param>
        /// <param name="customerClientLinkResourceName">The customer client link resource
        /// name.</param>
        /// <returns>The manager link resource name.</returns>
        private string GetManagerLinkResourceName(GoogleAdsClient client, long managerCustomerId,
                                                  long clientCustomerId, string customerClientLinkResourceName)
        {
            // Get the GoogleAdsService.
            GoogleAdsServiceClient googleAdsService =
                client.GetService(Services.V4.GoogleAdsService);

            // Create a client with the manager customer ID as login customer ID.
            client.Config.LoginCustomerId = managerCustomerId.ToString();

            // Creates the query.
            string query = "SELECT customer_client_link.manager_link_id FROM " +
                           "customer_client_link WHERE customer_client_link.resource_name = " +
                           $"'{customerClientLinkResourceName}'";

            // Issue a search request by specifying the page size.
            GoogleAdsRow result = googleAdsService.Search(
                managerCustomerId.ToString(), query).First();

            // Gets the ID and resource name associated to the manager link found.
            long   managerLinkId           = result.CustomerManagerLink.ManagerLinkId.Value;
            string managerLinkResourceName = ResourceNames.CustomerManagerLink(
                clientCustomerId, managerCustomerId, managerLinkId);

            // Prints the result.
            Console.WriteLine($"Retrieved the manager link of the customer client link: its ID " +
                              $"is {managerLinkId} and its resource name is '{managerLinkResourceName}'.");
            // Returns the resource name of the manager link found.
            return(managerLinkResourceName);
        }
示例#18
0
        /// <summary>
        /// Builds new ad group operations for the specified customer ID.
        /// </summary>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="campaignOperations">The campaign operations to be used to create ad
        /// groups.</param>
        /// <returns>The ad group operations.</returns>
        private static List <AdGroupOperation> BuildAdGroupOperations(
            long customerId, List <CampaignOperation> campaignOperations)
        {
            List <AdGroupOperation> operations = new List <AdGroupOperation>();

            foreach (CampaignOperation campaignOperation in campaignOperations)
            {
                for (int i = 0; i < NUMBER_OF_AD_GROUPS_TO_ADD; i++)
                {
                    // Creates an ad group.
                    long    adGroupId = GetNextTemporaryId();
                    AdGroup adGroup   = new AdGroup()
                    {
                        ResourceName = ResourceNames.AdGroup(customerId, adGroupId),
                        Name         = "batch job ad group #" + ExampleUtilities.GetShortRandomString(),
                        Campaign     = campaignOperation.Create.ResourceName,
                        Type         = AdGroupType.SearchStandard,
                        CpcBidMicros = 10_000_000
                    };

                    // Creates an ad group operation and adds it to the operations list.
                    AdGroupOperation op = new AdGroupOperation()
                    {
                        Create = adGroup
                    };
                    operations.Add(op);
                }
            }

            return(operations);
        }
示例#19
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for whom the conversion action will
        /// be added.</param>
        /// <param name="callerId">The caller ID in E.164 format with preceding '+' sign. e.g.
        /// "+16502531234".</param>
        /// <param name="callStartTime">The call start time in "yyyy-mm-dd hh:mm:ss+|-hh:mm"
        /// format.</param>
        /// <param name="conversionTime">The conversion time in "yyyy-mm-dd hh:mm:ss+|-hh:mm"
        /// format.</param>
        /// <param name="conversionValue">The conversion value.</param>
        /// <param name="conversionCustomVariableId">The ID of the conversion custom variable to
        /// associate with the upload.</param>
        /// <param name="conversionCustomVariableValue">The value of the conversion custom variable
        /// to associate with the upload.</param>
        // [START upload_call_conversion]
        public void Run(GoogleAdsClient client, long customerId, string callerId,
                        string callStartTime, string conversionTime, double conversionValue,
                        long?conversionCustomVariableId, string conversionCustomVariableValue)
        {
            // Get the ConversionUploadService.
            ConversionUploadServiceClient conversionUploadService =
                client.GetService(Services.V10.ConversionUploadService);

            // Create a call conversion by specifying currency as USD.
            CallConversion callConversion = new CallConversion()
            {
                CallerId           = callerId,
                CallStartDateTime  = callStartTime,
                ConversionDateTime = conversionTime,
                ConversionValue    = conversionValue,
                CurrencyCode       = "USD"
            };

            if (conversionCustomVariableId != null &&
                !string.IsNullOrEmpty(conversionCustomVariableValue))
            {
                callConversion.CustomVariables.Add(new CustomVariable()
                {
                    ConversionCustomVariable = ResourceNames.ConversionCustomVariable(
                        customerId, conversionCustomVariableId.Value),
                    Value = conversionCustomVariableValue
                });
            }

            UploadCallConversionsRequest request = new UploadCallConversionsRequest()
            {
                CustomerId     = customerId.ToString(),
                Conversions    = { callConversion },
                PartialFailure = true
            };

            try
            {
                // Issues a request to upload the call conversion. The partialFailure parameter
                // is set to true, and validateOnly parameter to false as required by this method
                // call.
                UploadCallConversionsResponse response =
                    conversionUploadService.UploadCallConversions(request);

                // Prints the result.
                CallConversionResult uploadedCallConversion = response.Results[0];
                Console.WriteLine($"Uploaded call conversion that occurred at " +
                                  $"'{uploadedCallConversion.CallStartDateTime}' for caller ID " +
                                  $"'{uploadedCallConversion.CallerId}' to the conversion action with " +
                                  $"resource name '{uploadedCallConversion.ConversionAction}'.");
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
示例#20
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>
        public void Run(GoogleAdsClient client, long customerId)
        {
            // Get the CustomerService.
            CustomerServiceClient customerService = client.GetService(Services.V4.CustomerService);

            try
            {
                string   customerResourceName = ResourceNames.Customer(customerId);
                Customer customer             = customerService.GetCustomer(customerResourceName);

                // Print account information.
                Console.WriteLine("Customer with ID {0}, descriptive name '{1}', currency " +
                                  "code '{2}', timezone '{3}', tracking URL template '{4}' and auto tagging " +
                                  "enabled '{5}' was retrieved.", customer.Id, customer.DescriptiveName,
                                  customer.CurrencyCode, customer.TimeZone, customer.TrackingUrlTemplate,
                                  customer.AutoTaggingEnabled);
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
示例#21
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for the conversion action is
        /// added.</param>
        /// <param name="conversionActionId">ID of the conversion action for which adjustments are
        /// uploaded.</param>
        /// <param name="adjustmentType">The type of adjustment.</param>
        /// <param name="conversionDateTime">The original conversion time.</param>
        /// <param name="gclid">The Google Click ID for which adjustments are uploaded.</param>
        /// <param name="adjustmentDateTime">The adjustment date and time.</param>
        /// <param name="restatementValue">The restatement value.</param>
        // [START UploadConversionAdjustment]
        public void Run(GoogleAdsClient client, long customerId, long conversionActionId,
                        string gclid, string conversionDateTime, string adjustmentDateTime,
                        ConversionAdjustmentType adjustmentType,
                        double?restatementValue)
        {
            // Get the ConversionAdjustmentUploadService.
            ConversionAdjustmentUploadServiceClient conversionAdjustmentUploadService =
                client.GetService(Services.V6.ConversionAdjustmentUploadService);

            // Associate conversion adjustments with the existing conversion action.
            // The GCLID should have been uploaded before with a conversion.
            ConversionAdjustment conversionAdjustment = new ConversionAdjustment()
            {
                ConversionAction  = ResourceNames.ConversionAction(customerId, conversionActionId),
                AdjustmentType    = adjustmentType,
                GclidDateTimePair = new GclidDateTimePair()
                {
                    Gclid = gclid,
                    ConversionDateTime = conversionDateTime,
                },
                AdjustmentDateTime = adjustmentDateTime,
            };

            // Set adjusted value for adjustment type RESTATEMENT.
            if (adjustmentType == ConversionAdjustmentType.Restatement)
            {
                conversionAdjustment.RestatementValue = new RestatementValue()
                {
                    AdjustedValue = restatementValue.Value
                };
            }

            try
            {
                // Issue a request to upload the conversion adjustment.
                UploadConversionAdjustmentsResponse response =
                    conversionAdjustmentUploadService.UploadConversionAdjustments(
                        new UploadConversionAdjustmentsRequest()
                {
                    CustomerId            = customerId.ToString(),
                    ConversionAdjustments = { conversionAdjustment },
                    PartialFailure        = true,
                    ValidateOnly          = false
                });

                ConversionAdjustmentResult result = response.Results[0];
                // Print the result.
                Console.WriteLine($"Uploaded conversion adjustment value of" +
                                  $" '{result.ConversionAction}' for Google Click ID " +
                                  $"'{result.GclidDateTimePair.Gclid}'");
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
        /// <summary>
        /// Creates and returns a new Billing Setup instance with complete payment details. One of
        /// paymentsAccountId or paymentsProfileId must be provided.
        /// </summary>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="paymentsAccountId">Optional payments account ID to attach to the new
        ///     billing setup. Must be formatted as "1234-5678-9012-3456".</param>
        /// <param name="paymentsProfileId">Optional payments profile ID to attach to a new payments
        ///     account and to the new billing setup. Must be formatted as "1234-5678-9012".</param>
        /// <returns>A new BillingSetup instance with complete payment details.</returns>
        /// <exception cref="Exception">Generic exception if no payment details have been
        ///     provided.</exception>
        private BillingSetup CreateBillingSetup(long customerId, string paymentsAccountId,
                                                string paymentsProfileId)
        {
            BillingSetup billingSetup = new BillingSetup();

            // Sets the appropriate payments account field.
            if (paymentsAccountId != null)
            {
                // If a payments account id has been provided, set PaymentsAccount to its resource
                // name. You can list available payments accounts via the PaymentsAccountService's
                // ListPaymentsAccounts method.
                billingSetup.PaymentsAccount =
                    ResourceNames.PaymentsAccount(customerId, paymentsAccountId);
            }
            else if (paymentsProfileId != null)
            {
                // Otherwise, create a new payments account by setting the PaymentsAccountInfo
                // field. See https://support.google.com/google-ads/answer/7268503 for information
                // about payments profiles.
                billingSetup.PaymentsAccountInfo = new BillingSetup.Types.PaymentsAccountInfo()
                {
                    PaymentsAccountName = "Payments Account #" + ExampleUtilities.GetRandomString(),
                    PaymentsProfileId   = paymentsProfileId
                };
            }
            else
            {
                throw new Exception("No paymentsAccountId or paymentsProfileId provided.");
            }

            return(billingSetup);
        }
        /// <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="keywordPlanId">The keyword plan ID.</param>
        public void Run(GoogleAdsClient client, long customerId, long keywordPlanId)
        {
            KeywordPlanServiceClient kpServiceClient =
                client.GetService(Services.V4.KeywordPlanService);
            string keywordPlanResource = ResourceNames.KeywordPlan(customerId, keywordPlanId);

            try
            {
                GenerateForecastMetricsResponse response = kpServiceClient.GenerateForecastMetrics(
                    keywordPlanResource);
                int i = 0;
                foreach (KeywordPlanKeywordForecast forecast in response.KeywordForecasts)
                {
                    ForecastMetrics metrics = forecast.KeywordForecast;
                    Console.WriteLine($"{++i}) Keyword ID: {forecast.KeywordPlanAdGroupKeyword}");
                    Console.WriteLine($"Estimated daily clicks: {metrics.Clicks}");
                    Console.WriteLine($"Estimated daily impressions: {metrics.Impressions}");
                    Console.WriteLine($"Estimated average cpc (micros): {metrics.AverageCpc}\n");
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
        /// <summary>
        /// Creates a campaign feed, which tells Google Ads which campaigns to use the provided
        /// data with.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="campaignId">The campaign to receive the feed.</param>
        /// <param name="feed">The feed to connect to the campaign.</param>
        private void CreateCampaignFeed(GoogleAdsClient client, long customerId, long campaignId,
                                        Feed feed)
        {
            CampaignFeedServiceClient campaignFeedServiceClient =
                client.GetService(Services.V5.CampaignFeedService);

            // Fetch the Feed Item IDs and collapse them into a single comma-separated string.
            List <long>  feedItemIds           = feed.Attributes.Select(attr => attr.Id.Value).ToList();
            string       aggregatedFeedItemIds = string.Join(",", feedItemIds);
            CampaignFeed campaignFeed          = new CampaignFeed()
            {
                Feed             = feed.ResourceName,
                Campaign         = ResourceNames.Campaign(customerId, campaignId),
                MatchingFunction = new MatchingFunction()
                {
                    FunctionString = $"AND(IN(FEED_ITEM_ID,{{ {aggregatedFeedItemIds} }})," +
                                     "EQUALS(CONTEXT.DEVICE,'Mobile'))"
                }
            };

            campaignFeed.PlaceholderTypes.Add(PlaceholderTypeEnum.Types.PlaceholderType.Sitelink);

            CampaignFeedOperation operation = new CampaignFeedOperation()
            {
                Create = campaignFeed
            };

            MutateCampaignFeedsResponse response = campaignFeedServiceClient.MutateCampaignFeeds(
                customerId.ToString(), new[] { operation });

            Console.WriteLine($"Created campaign feed '{response.Results.First().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="campaignId">ID of the campaign to be removed.</param>
        public void Run(GoogleAdsClient client, long customerId, long campaignId)
        {
            // Get the CampaignService.
            CampaignServiceClient campaignService = client.GetService(Services.V10.CampaignService);

            // Create the operation, and set the Remove field to the resource name of the
            // campaign to be removed.
            CampaignOperation operation = new CampaignOperation()
            {
                Remove = ResourceNames.Campaign(customerId, campaignId)
            };

            try
            {
                // Remove the campaign.
                MutateCampaignsResponse retVal = campaignService.MutateCampaigns(
                    customerId.ToString(), new CampaignOperation[] { operation });

                // Display the results.
                foreach (MutateCampaignResult removedCampaign in retVal.Results)
                {
                    Console.WriteLine($"Campaign with resource name = '{0}' was removed.",
                                      removedCampaign.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>
        /// Targets the specified user list to 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 campaign resource name.</param>
        /// <param name="userListId">The user list ID.</param>
        private void AttachUserList(GoogleAdsClient client, long customerId,
                                    string adGroupResourceName, long userListId)
        {
            // Creates the ad group criterion service client.
            AdGroupCriterionServiceClient adGroupCriterionServiceClient = client.GetService
                                                                              (Services.V5.AdGroupCriterionService);

            string userListResourceName = ResourceNames.UserList(customerId, userListId);

            // Creates the ad group criterion that targets the user list.
            AdGroupCriterion adGroupCriterion = new AdGroupCriterion()
            {
                AdGroup  = adGroupResourceName,
                UserList = new UserListInfo()
                {
                    UserList = userListResourceName
                }
            };

            // Creates the ad group criterion operation.
            AdGroupCriterionOperation operation = new AdGroupCriterionOperation()
            {
                Create = adGroupCriterion
            };

            // Adds the ad group criterion.
            MutateAdGroupCriteriaResponse response = adGroupCriterionServiceClient
                                                     .MutateAdGroupCriteria(customerId.ToString(), new[] { operation });

            Console.WriteLine("Created ad group criterion with resource name " +
                              $"'{response.Results.First().ResourceName}'.");
        }
示例#27
0
        /// <summary>
        /// Creates a new criterion containing a subdivision listing group node.
        /// </summary>
        /// <param name="customerId">The client customer ID.</param>
        /// <param name="adGroupId">The ID of the ad group.</param>
        /// <param name="adGroupCriterionId">The ID of the criterion. This value will used to
        /// construct the resource name. This can be a negative number if the criterion is yet to
        /// be created.</param>
        /// <param name="parentAdGroupCriterionResourceName">The resource name of the parent of
        /// this criterion.</param>
        /// <param name="listingDimensionInfo">The ListingDimensionInfo to be set for this listing
        /// group.</param>
        /// <returns>The ad group criterion object that contains the subdivision listing group
        /// node.</returns>
        private AdGroupCriterion CreateListingGroupSubdivision(long customerId, long adGroupId,
                                                               long adGroupCriterionId, String parentAdGroupCriterionResourceName,
                                                               ListingDimensionInfo listingDimensionInfo)
        {
            String adGroupCriterionResourceName = ResourceNames.AdGroupCriterion(
                customerId, adGroupId, adGroupCriterionId);

            AdGroupCriterion adGroupCriterion = new AdGroupCriterion()
            {
                // The resource name the criterion will be created with. This will define the
                // ID for the ad group criterion.
                ResourceName = adGroupCriterionResourceName,
                Status       = AdGroupCriterionStatus.Enabled,
                ListingGroup = new ListingGroupInfo()
                {
                    Type = ListingGroupType.Subdivision,

                    // Set the ad group criterion resource name for the parent listing group.
                    // This can include a criterion ID if the parent criterion is not yet created.
                    // Use StringValue to convert from a String to a compatible argument type.
                    ParentAdGroupCriterion = parentAdGroupCriterionResourceName,

                    // Case values contain the listing dimension used for the node.
                    CaseValue = listingDimensionInfo
                }
            };

            return(adGroupCriterion);
        }
示例#28
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;
            }
        }
示例#29
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">The ad group to which new keyword ia added.</param>
        /// <param name="keywordText">The new keyword text.</param>
        public void Run(GoogleAdsClient client, long customerId, long adGroupId, string keywordText)
        {
            if (string.IsNullOrEmpty(keywordText))
            {
                keywordText = KEYWORD_TEXT;
            }
            // Get the AdGroupCriterionService.
            AdGroupCriterionServiceClient adGroupCriterionService =
                client.GetService(Services.V6.AdGroupCriterionService);

            // Create a keyword.
            AdGroupCriterion criterion = new AdGroupCriterion()
            {
                AdGroup = ResourceNames.AdGroup(customerId, adGroupId),
                Status  = AdGroupCriterionStatus.Enabled,
                Keyword = new KeywordInfo()
                {
                    Text      = keywordText,
                    MatchType = KeywordMatchType.Exact
                }
            };

            // Create the operation.
            AdGroupCriterionOperation operation = new AdGroupCriterionOperation()
            {
                Create = criterion,
            };

            try
            {
                // Add the keywords.
                MutateAdGroupCriteriaResponse retVal =
                    adGroupCriterionService.MutateAdGroupCriteria(customerId.ToString(),
                                                                  new AdGroupCriterionOperation[] { operation });

                // Display the results.
                if (retVal.Results.Count > 0)
                {
                    foreach (MutateAdGroupCriterionResult newCriterion in retVal.Results)
                    {
                        Console.WriteLine($"Created keyword with resource ID = " +
                                          "'{newCriterion.ResourceName}'.");
                    }
                }
                else
                {
                    Console.WriteLine("No keywords were added.");
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
示例#30
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 keywords are added.</param>
        /// <param name="keywordText">The keyword text to add to the ad group.</param>
        public void Run(GoogleAdsClient client, long customerId, long adGroupId,
                        string keywordText)
        {
            // Get the AdGroupCriterionServiceClient.
            AdGroupCriterionServiceClient service = client.GetService(
                Services.V4.AdGroupCriterionService);

            // Configures the keyword text and match type settings.
            KeywordInfo keywordInfo = new KeywordInfo()
            {
                Text      = keywordText,
                MatchType = KeywordMatchType.Exact
            };

            // Constructs an ad group criterion using the keyword text info above.
            AdGroupCriterion adGroupCriterion = new AdGroupCriterion()
            {
                AdGroup = ResourceNames.AdGroup(customerId, adGroupId),
                Status  = AdGroupCriterionStatus.Paused,
                Keyword = keywordInfo
            };

            AdGroupCriterionOperation operation = new AdGroupCriterionOperation()
            {
                Create = adGroupCriterion
            };

            try
            {
                try
                {
                    // Try sending a mutate request to add the keyword.
                    MutateAdGroupCriteriaResponse response = service.MutateAdGroupCriteria(
                        customerId.ToString(), new[] { operation });
                    Console.WriteLine($"Added a keyword with resource name " +
                                      $"'{response.Results[0].ResourceName}'.");
                }
                catch (GoogleAdsException ex)
                {
                    PolicyViolationKey[] exemptPolicyViolationKeys =
                        FetchExemptPolicyViolationKeys(ex);

                    // Try sending exemption requests for creating a keyword. However, if your
                    // keyword contains many policy violations, but not all of them are exemptible,
                    // the request will not be sent.
                    RequestExemption(customerId, service, operation, exemptPolicyViolationKeys);
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
 public string GetString(ResourceNames.MainWindow resourceName)
 {
     string resource = string.Empty;
     switch (resourceName)
     {
         case ResourceNames.MainWindow.Title:
             resource = ProductName;
             break;
     }
     return EnsureStringLoaded(resource, resourceName.ToString());
 }
        public string GetString(ResourceNames.ConsentForm resourceName)
        {
            string resource = string.Empty;
            switch (resourceName)
            {
                case ResourceNames.ConsentForm.Title:
                    resource = string.Format(Properties.Resources.UsageReportPromptDialogTitle,ProductName);
                    break;
            }

            return EnsureStringLoaded(resource, resourceName.ToString());
        }
 public ImageSource GetImageSource(ResourceNames.StartPage resourceName)
 {
     ImageSource image = null;
     switch (resourceName)
     {
         case ResourceNames.StartPage.Image:
             image = new BitmapImage(
                 new Uri("pack://application:,,,/DynamoCoreWpf;component/UI/Images/StartPage/dynamo-logo.png",
                     UriKind.Absolute));
             break;
     }
     return EnsureImageLoaded(image, resourceName.ToString());
 }
 public ImageSource GetImageSource(ResourceNames.ConsentForm resourceName)
 {
     ImageSource image = null;
     switch (resourceName)
     {
         case ResourceNames.ConsentForm.Image:
             image = new BitmapImage(
                 new Uri(@"pack://application:,,,/DynamoCoreWpf;component/UI/Images/consent_form_image.png",
                     UriKind.Absolute));
             break;
     }
     return EnsureImageLoaded(image, resourceName.ToString());
 }
示例#35
0
 public ResourceCost(ResourceNames item, int amount)
 {
     this.item = item;
     this.amount = amount;
 }