/// <summary>
        /// Creates the budget for the 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>
        /// <returns>The resource name of the newly created campaign budget.</returns>
        private static string CreateBudget(GoogleAdsClient client, long customerId)
        {
            // Get the BudgetService.
            CampaignBudgetServiceClient budgetService = client.GetService(
                Services.V4.CampaignBudgetService);

            // Create the campaign budget.
            CampaignBudget budget = new CampaignBudget()
            {
                Name           = "Interplanetary Cruise Budget #" + ExampleUtilities.GetRandomString(),
                DeliveryMethod = BudgetDeliveryMethod.Standard,
                AmountMicros   = 500000
            };

            // Create the operation.
            CampaignBudgetOperation budgetOperation = new CampaignBudgetOperation()
            {
                Create = budget
            };

            // Create the campaign budget.
            MutateCampaignBudgetsResponse response = budgetService.MutateCampaignBudgets(
                customerId.ToString(), new CampaignBudgetOperation[] { budgetOperation });

            return(response.Results[0].ResourceName);
        }
        /// <summary>
        /// Creates a shared campaign budget to be used to create the 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="name">The budget name.</param>
        /// <param name="amount">The budget amount in micros.</param>
        /// <returns>The budget resource name.</returns>
        private string CreateSharedBudget(GoogleAdsClient client, long customerId, string name,
                                          long amount)
        {
            // Get the CampaignBudgetService.
            CampaignBudgetServiceClient campaignBudgetService =
                client.GetService(Services.V1.CampaignBudgetService);

            // Create a shared budget.
            CampaignBudget budget = new CampaignBudget()
            {
                Name             = name,
                AmountMicros     = amount,
                DeliveryMethod   = BudgetDeliveryMethodEnum.Types.BudgetDeliveryMethod.Standard,
                ExplicitlyShared = true
            };

            // Create the operation.
            CampaignBudgetOperation campaignBudgetOperation = new CampaignBudgetOperation()
            {
                Create = budget
            };

            // Make the mutate request.
            MutateCampaignBudgetsResponse retVal = campaignBudgetService.MutateCampaignBudgets(
                customerId.ToString(), new CampaignBudgetOperation[] { campaignBudgetOperation });

            return(retVal.Results[0].ResourceName);
        }
示例#3
0
        /// <summary>
        /// Creates a new campaign budget in the specified client account.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <returns>The resource name of the newly created budget.</returns>
        private static string AddCampaignBudget(GoogleAdsClient client, long customerId)
        {
            // Get the CampaignBudgetService.
            CampaignBudgetServiceClient service = client.GetService(
                Services.V4.CampaignBudgetService);

            // Create a campaign budget.
            CampaignBudget budget = new CampaignBudget()
            {
                Name           = "Interplanetary Cruise Budget #" + ExampleUtilities.GetRandomString(),
                DeliveryMethod = BudgetDeliveryMethod.Standard,
                AmountMicros   = 50000000
            };

            // Create a campaign budget operation.
            CampaignBudgetOperation campaignBudgetOperation = new CampaignBudgetOperation()
            {
                Create = budget
            };

            // Create the budget.
            MutateCampaignBudgetsResponse response = service.MutateCampaignBudgets(
                customerId.ToString(), new CampaignBudgetOperation[] { campaignBudgetOperation });

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

            Console.WriteLine($"Added a budget with resource name: '{budgetResourceName}'.");
            return(budgetResourceName);
        }
示例#4
0
        /// <summary>
        /// Creates a new campaign budget in the specified client account.
        /// </summary>
        /// <param name="client">The Google Ads API client.</param>
        /// <param name="customerId">The client customer ID.</param>
        /// <returns>Resource name of the newly created budget.</returns>
        /// <exception cref="GoogleAdsException">Thrown if an API request failed with one or more
        /// service errors.</exception>
        private string AddCampaignBudget(GoogleAdsClient client, long customerId)
        {
            // Get the CampaignBudgetService.
            CampaignBudgetServiceClient campaignBudgetService =
                client.GetService(Services.V6.CampaignBudgetService);

            CampaignBudget budget = new CampaignBudget()
            {
                Name           = "Interplanetary Cruise Budget #" + ExampleUtilities.GetRandomString(),
                DeliveryMethod = BudgetDeliveryMethod.Standard,
                AmountMicros   = 5_000_000L,
                // Budgets for Smart Shopping campaigns cannot be shared.
                ExplicitlyShared = false
            };

            CampaignBudgetOperation operation = new CampaignBudgetOperation()
            {
                Create = budget
            };

            MutateCampaignBudgetsResponse response =
                campaignBudgetService.MutateCampaignBudgets(customerId.ToString(),
                                                            new CampaignBudgetOperation[] { operation });
            string budgetResourceName = response.Results[0].ResourceName;

            Console.WriteLine("Added a budget with resource name: '{0}'.", budgetResourceName);
            return(budgetResourceName);
        }
        /// <summary>
        /// Adds a campaign budget.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <returns>The campaign budget resource name.</returns>
        private static string AddCampaignBudget(GoogleAdsClient client, long customerId)
        {
            // Get the CampaignBudgetService.
            CampaignBudgetServiceClient campaignBudgetService =
                client.GetService(Services.V3.CampaignBudgetService);

            // Create the budget.
            CampaignBudget campaignBudget = new CampaignBudget()
            {
                Name           = "",
                AmountMicros   = 3_000_000,
                DeliveryMethod = BudgetDeliveryMethod.Standard
            };

            // Create the operation.
            CampaignBudgetOperation operation = new CampaignBudgetOperation()
            {
                Create = campaignBudget
            };

            // Add the campaign budget.
            MutateCampaignBudgetsResponse response =
                campaignBudgetService.MutateCampaignBudgets(customerId.ToString(),
                                                            new CampaignBudgetOperation[] { operation });
            // Display the result.

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

            Console.WriteLine($"Added budget with resource name '{budgetResourceName}'.");
            return(budgetResourceName);
        }
示例#6
0
        /// <summary>
        /// Creates the budget for the 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>
        /// <returns>The resource name of the newly created campaign budget.</returns>
        private string CreateBudget(GoogleAdsClient client, long customerId)
        {
            // Get the BudgetService.
            CampaignBudgetServiceClient budgetService = client.GetService(
                Services.V4.CampaignBudgetService);

            // Creates a campaign budget.
            CampaignBudget budget = new CampaignBudget()
            {
                Name           = "Interplanetary Cruise Budget #" + ExampleUtilities.GetRandomString(),
                DeliveryMethod = BudgetDeliveryMethod.Standard,
                AmountMicros   = 50_000_000,
                // An App campaign cannot use a shared campaign budget.
                // explicitly_shared must be set to false.
                ExplicitlyShared = false
            };

            // Create the operation.
            CampaignBudgetOperation budgetOperation = new CampaignBudgetOperation()
            {
                Create = budget
            };

            // Create the campaign budget.
            MutateCampaignBudgetsResponse response = budgetService.MutateCampaignBudgets(
                customerId.ToString(), new CampaignBudgetOperation[] { budgetOperation });

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

            Console.WriteLine($"Created campaign budget with resource name " +
                              $"'{budgetResourceName}'.");

            return(budgetResourceName);
        }
示例#7
0
        /// <summary>
        /// Creates the budget for the 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>
        /// <returns>The resource name of the newly created campaign budget.</returns>
        private static string CreateBudget(GoogleAdsClient client, long customerId)
        {
            // Get the BudgetService.
            CampaignBudgetServiceClient budgetService = client.GetService(
                Services.V3.CampaignBudgetService);

            // Create the campaign budget.
            CampaignBudget budget = new CampaignBudget()
            {
                Name           = "Interplanetary Cruise Budget #" + ExampleUtilities.GetRandomString(),
                DeliveryMethod = BudgetDeliveryMethod.Standard,
                AmountMicros   = 500000
            };

            // Create the operation.
            CampaignBudgetOperation budgetOperation = new CampaignBudgetOperation()
            {
                Create = budget
            };

            // Create the campaign budget.
            MutateCampaignBudgetsResponse response = budgetService.MutateCampaignBudgets(
                customerId.ToString(), new CampaignBudgetOperation[] { budgetOperation });

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

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

            return(budgetResourceName);
        }
 /// <summary>Snippet for MutateCampaignBudgets</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void MutateCampaignBudgets()
 {
     // Create client
     CampaignBudgetServiceClient campaignBudgetServiceClient = CampaignBudgetServiceClient.Create();
     // Initialize request argument(s)
     string customerId = "";
     IEnumerable <CampaignBudgetOperation> operations = new CampaignBudgetOperation[]
     {
         new CampaignBudgetOperation(),
     };
     // Make the request
     MutateCampaignBudgetsResponse response = campaignBudgetServiceClient.MutateCampaignBudgets(customerId, operations);
 }
示例#9
0
 /// <summary>Snippet for MutateCampaignBudgets</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void MutateCampaignBudgetsRequestObject()
 {
     // Create client
     CampaignBudgetServiceClient campaignBudgetServiceClient = CampaignBudgetServiceClient.Create();
     // Initialize request argument(s)
     MutateCampaignBudgetsRequest request = new MutateCampaignBudgetsRequest
     {
         CustomerId = "",
         Operations =
         {
             new CampaignBudgetOperation(),
         },
         PartialFailure = false,
         ValidateOnly   = false,
     };
     // Make the request
     MutateCampaignBudgetsResponse response = campaignBudgetServiceClient.MutateCampaignBudgets(request);
 }
 /// <summary>Snippet for MutateCampaignBudgets</summary>
 public void MutateCampaignBudgetsRequestObject()
 {
     // Snippet: MutateCampaignBudgets(MutateCampaignBudgetsRequest, CallSettings)
     // Create client
     CampaignBudgetServiceClient campaignBudgetServiceClient = CampaignBudgetServiceClient.Create();
     // Initialize request argument(s)
     MutateCampaignBudgetsRequest request = new MutateCampaignBudgetsRequest
     {
         CustomerId = "",
         Operations =
         {
             new CampaignBudgetOperation(),
         },
         PartialFailure      = false,
         ValidateOnly        = false,
         ResponseContentType = ResponseContentTypeEnum.Types.ResponseContentType.Unspecified,
     };
     // Make the request
     MutateCampaignBudgetsResponse response = campaignBudgetServiceClient.MutateCampaignBudgets(request);
     // End snippet
 }