Пример #1
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="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.V4.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;
            }
        }
Пример #2
0
        // [END list_accessible_strategies]

        // [START attach_strategy]
        /// <summary>
        /// Attaches a specified cross-account bidding strategy to a campaign owned by a specified
        /// client customer account.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads client customer ID for which the call is
        /// made.</param>
        /// <param name="campaignId">The ID of the campaign owned by the customer ID to which the
        /// cross-account bidding strategy will be attached.</param>
        /// <param name="biddingStrategyResourceName">A cross-account bidding strategy resource
        /// name.</param>
        private void AttachCrossAccountBiddingStrategyToCampaign(GoogleAdsClient client,
                                                                 long customerId, long campaignId, string biddingStrategyResourceName)
        {
            CampaignServiceClient campaignServiceClient =
                client.GetService(Services.V10.CampaignService);

            Campaign campaign = new Campaign
            {
                ResourceName    = ResourceNames.Campaign(customerId, campaignId),
                BiddingStrategy = biddingStrategyResourceName
            };

            // Mutate the campaign and print the resource name of the updated campaign.
            MutateCampaignsResponse mutateCampaignsResponse =
                campaignServiceClient.MutateCampaigns(customerId.ToString(), new[]
            {
                new CampaignOperation
                {
                    Update     = campaign,
                    UpdateMask = FieldMasks.AllSetFieldsOf(campaign)
                }
            });

            Console.WriteLine("Updated campaign with resource name " +
                              $"'{mutateCampaignsResponse.Results.First().ResourceName}'.");
        }
Пример #3
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}");
            }
        }
Пример #4
0
 /// <summary>Snippet for GetCampaign</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetCampaignResourceNames()
 {
     // Create client
     CampaignServiceClient campaignServiceClient = CampaignServiceClient.Create();
     // Initialize request argument(s)
     CampaignName resourceName = CampaignName.FromCustomerCampaign("[CUSTOMER_ID]", "[CAMPAIGN_ID]");
     // Make the request
     Campaign response = campaignServiceClient.GetCampaign(resourceName);
 }
 /// <summary>Snippet for GetCampaign</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetCampaign()
 {
     // Create client
     CampaignServiceClient campaignServiceClient = CampaignServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER]/campaigns/[CAMPAIGN]";
     // Make the request
     Campaign response = campaignServiceClient.GetCampaign(resourceName);
 }
Пример #6
0
        /// <summary>
        /// Creates a new hotel campaign 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>
        /// <param name="budgetResourceName">The resource name of budget for a new campaign.
        /// </param>
        /// <param name="hotelCenterAccountId">The Hotel Center account ID.</param>
        /// <param name="cpcBidCeilingMicroAmount">The CPC bid ceiling micro amount.</param>
        /// <returns>The resource name of the newly created campaign.</returns>
        private static string AddHotelCampaign(GoogleAdsClient client, long customerId,
                                               string budgetResourceName, long hotelCenterAccountId, long cpcBidCeilingMicroAmount)
        {
            // Get the CampaignService.
            CampaignServiceClient service = client.GetService(Services.V6.CampaignService);

            // [START AddHotelAd_2]
            // Create a campaign.
            Campaign campaign = new Campaign()
            {
                Name = "Interplanetary Cruise Campaign #" + ExampleUtilities.GetRandomString(),

                // Configure settings related to hotel campaigns including advertising channel type
                // and hotel setting info.
                AdvertisingChannelType = AdvertisingChannelType.Hotel,
                HotelSetting           = new HotelSettingInfo()
                {
                    HotelCenterId = hotelCenterAccountId
                },

                // 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 to PercentCpc. Only Manual CPC and Percent CPC can
                // be used for hotel campaigns.
                PercentCpc = new PercentCpc()
                {
                    CpcBidCeilingMicros = cpcBidCeilingMicroAmount
                },

                // Set the budget.
                CampaignBudget = budgetResourceName,

                // Configure the campaign network options. Only Google Search is allowed for
                // hotel campaigns.
                NetworkSettings = new NetworkSettings()
                {
                    TargetGoogleSearch = true
                }
            };
            // [END AddHotelAd_2]

            // Create a campaign operation.
            CampaignOperation campaignOperation = new CampaignOperation()
            {
                Create = campaign
            };

            // Issue a mutate request to add campaigns.
            MutateCampaignsResponse response = service.MutateCampaigns(customerId.ToString(),
                                                                       new CampaignOperation[] { campaignOperation });

            return(response.Results[0].ResourceName);
        }
Пример #7
0
        /// <summary>Snippet for GetCampaignAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetCampaignAsync()
        {
            // Create client
            CampaignServiceClient campaignServiceClient = await CampaignServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER_ID]/campaigns/[CAMPAIGN_ID]";
            // Make the request
            Campaign response = await campaignServiceClient.GetCampaignAsync(resourceName);
        }
        /// <summary>Snippet for GetCampaignAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetCampaignResourceNamesAsync()
        {
            // Create client
            CampaignServiceClient campaignServiceClient = await CampaignServiceClient.CreateAsync();

            // Initialize request argument(s)
            CampaignName resourceName = CampaignName.FromCustomerCampaign("[CUSTOMER]", "[CAMPAIGN]");
            // Make the request
            Campaign response = await campaignServiceClient.GetCampaignAsync(resourceName);
        }
 public static IDictionary<int, string> GetCampaigns(string ticket, int advertiserId)
 {
     var client = new CampaignServiceClient();
     return client.GetCampaigns(ticket, new GetCampaignsData
                                            {
                                                AdvertiserId = advertiserId
                                            })
                  .Select(p => new {p.Id, p.Name})
                  .ToDictionary(kvp => kvp.Id.Value, kvp => kvp.Name);
 }
Пример #10
0
        /// <summary>
        /// Creates the smart display 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="budgetResourceName">The campaign budget resource name.</param>
        /// <returns>Resource name of the newly created campaign.</returns>
        private string CreateSmartDisplayCampaign(GoogleAdsClient client, long customerId,
                                                  string budgetResourceName)
        {
            // Get the CampaignService.
            CampaignServiceClient campaignService = client.GetService(Services.V3.CampaignService);

            // Create the campaign.
            Campaign campaign = new Campaign()
            {
                Name = "Smart Display Campaign #" + ExampleUtilities.GetRandomString(),

                // Smart Display campaign requires the advertising_channel_type as 'DISPLAY'.
                AdvertisingChannelType = AdvertisingChannelType.Display,

                // Smart Display campaign requires the advertising_channel_sub_type as
                // 'DISPLAY_SMART_CAMPAIGN'.
                AdvertisingChannelSubType = AdvertisingChannelSubType.DisplaySmartCampaign,

                // 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,

                // Smart Display campaign requires the TargetCpa bidding strategy.
                TargetCpa = new TargetCpa()
                {
                    TargetCpaMicros = 5000000
                },

                CampaignBudget = budgetResourceName,

                // Optional: Set the start date.
                StartDate = DateTime.Now.AddDays(1).ToString("yyyyMMdd"),

                // Optional: Set the end date.
                EndDate = DateTime.Now.AddYears(1).ToString("yyyyMMdd"),
            };

            // Create the operation.
            CampaignOperation operation = new CampaignOperation()
            {
                Create = campaign
            };

            // Add the campaign.
            MutateCampaignsResponse response = campaignService.MutateCampaigns(
                customerId.ToString(), new[] { operation });

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

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

            return(campaignResourceName);
        }
Пример #11
0
 /// <summary>Snippet for GetCampaign</summary>
 public void GetCampaign()
 {
     // Snippet: GetCampaign(string, CallSettings)
     // Create client
     CampaignServiceClient campaignServiceClient = CampaignServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER_ID]/campaigns/[CAMPAIGN_ID]";
     // Make the request
     Campaign response = campaignServiceClient.GetCampaign(resourceName);
     // End snippet
 }
Пример #12
0
        public static IDictionary <int, string> GetCampaigns(string ticket, int advertiserId)
        {
            var client = new CampaignServiceClient();

            return(client.GetCampaigns(ticket, new GetCampaignsData
            {
                AdvertiserId = advertiserId
            })
                   .Select(p => new { p.Id, p.Name })
                   .ToDictionary(kvp => kvp.Id.Value, kvp => kvp.Name));
        }
Пример #13
0
 /// <summary>Snippet for GetCampaign</summary>
 public void GetCampaignResourceNames()
 {
     // Snippet: GetCampaign(CampaignName, CallSettings)
     // Create client
     CampaignServiceClient campaignServiceClient = CampaignServiceClient.Create();
     // Initialize request argument(s)
     CampaignName resourceName = CampaignName.FromCustomerCampaign("[CUSTOMER]", "[CAMPAIGN]");
     // Make the request
     Campaign response = campaignServiceClient.GetCampaign(resourceName);
     // End snippet
 }
 /// <summary>Snippet for GetCampaign</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetCampaignRequestObject()
 {
     // Create client
     CampaignServiceClient campaignServiceClient = CampaignServiceClient.Create();
     // Initialize request argument(s)
     GetCampaignRequest request = new GetCampaignRequest
     {
         ResourceNameAsCampaignName = CampaignName.FromCustomerCampaign("[CUSTOMER]", "[CAMPAIGN]"),
     };
     // Make the request
     Campaign response = campaignServiceClient.GetCampaign(request);
 }
 /// <summary>Snippet for MutateCampaigns</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void MutateCampaigns()
 {
     // Create client
     CampaignServiceClient campaignServiceClient = CampaignServiceClient.Create();
     // Initialize request argument(s)
     string customerId = "";
     IEnumerable <CampaignOperation> operations = new CampaignOperation[]
     {
         new CampaignOperation(),
     };
     // Make the request
     MutateCampaignsResponse response = campaignServiceClient.MutateCampaigns(customerId, operations);
 }
        /// <summary>Snippet for GetCampaignAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetCampaignRequestObjectAsync()
        {
            // Create client
            CampaignServiceClient campaignServiceClient = await CampaignServiceClient.CreateAsync();

            // Initialize request argument(s)
            GetCampaignRequest request = new GetCampaignRequest
            {
                ResourceNameAsCampaignName = CampaignName.FromCustomerCampaign("[CUSTOMER_ID]", "[CAMPAIGN_ID]"),
            };
            // Make the request
            Campaign response = await campaignServiceClient.GetCampaignAsync(request);
        }
Пример #17
0
        public static void getCampaignId()
        {
            CampaignServiceClient client = new CampaignServiceClient();

            AuthHeader authHeader = new AuthHeader();

            HeaderUtil.loadHeader(authHeader);

            long[]    result    = null;
            ResHeader resHeader = client.getCampaignId(authHeader, out result);

            Console.WriteLine("CampaignService.getCampaignId(): ");
            ObjectDumper.WriteResponse(resHeader, result);
        }
Пример #18
0
        /// <summary>Snippet for GetCampaignAsync</summary>
        public async Task GetCampaignResourceNamesAsync()
        {
            // Snippet: GetCampaignAsync(CampaignName, CallSettings)
            // Additional: GetCampaignAsync(CampaignName, CancellationToken)
            // Create client
            CampaignServiceClient campaignServiceClient = await CampaignServiceClient.CreateAsync();

            // Initialize request argument(s)
            CampaignName resourceName = CampaignName.FromCustomerCampaign("[CUSTOMER]", "[CAMPAIGN]");
            // Make the request
            Campaign response = await campaignServiceClient.GetCampaignAsync(resourceName);

            // End snippet
        }
Пример #19
0
        /// <summary>Snippet for GetCampaignAsync</summary>
        public async Task GetCampaignAsync()
        {
            // Snippet: GetCampaignAsync(string, CallSettings)
            // Additional: GetCampaignAsync(string, CancellationToken)
            // Create client
            CampaignServiceClient campaignServiceClient = await CampaignServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER]/campaigns/[CAMPAIGN]";
            // Make the request
            Campaign response = await campaignServiceClient.GetCampaignAsync(resourceName);

            // End snippet
        }
Пример #20
0
        // [END use_portfolio_bidding_strategy]

        /// <summary>
        /// Creates the campaign with a portfolio bidding strategy.
        /// </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 campaign name.</param>
        /// <param name="biddingStrategyResourceName">The bidding strategy id.</param>
        /// <param name="campaignBudgetResourceName">The campaign budget resource name.</param>
        /// <returns>The campaign resource name.</returns>
        private string CreateCampaignWithBiddingStrategy(GoogleAdsClient client,
                                                         long customerId, string name, string biddingStrategyResourceName,
                                                         string campaignBudgetResourceName)
        {
            // Get the CampaignService.
            CampaignServiceClient campaignService = client.GetService(Services.V10.CampaignService);

            // [START use_portfolio_bidding_strategy_2]
            // Create the campaign.
            Campaign campaign = new Campaign()
            {
                Name = name,
                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,

                // Set the campaign budget.
                CampaignBudget = campaignBudgetResourceName,

                // Set bidding strategy (required).
                BiddingStrategy = biddingStrategyResourceName,

                // Set the campaign network options.
                NetworkSettings = new NetworkSettings()
                {
                    TargetGoogleSearch         = true,
                    TargetSearchNetwork        = true,
                    TargetContentNetwork       = true,
                    TargetPartnerSearchNetwork = false
                }
            };
            // [END use_portfolio_bidding_strategy_2]

            // Create the operation.
            CampaignOperation operation = new CampaignOperation()
            {
                Create = campaign
            };

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

            return(retVal.Results[0].ResourceName);
        }
Пример #21
0
        // [END AddMerchantCenterDynamicRemarketingCampaign]

        /// <summary>
        /// Creates a campaign linked to a Merchant Center product feed.
        /// </summary>
        /// <param name="client">The Google Ads API client.</param>
        /// <param name="customerId">The client customer ID.</param>
        /// <param name="merchantCenterAccountId">The Merchant Center account ID.</param>
        /// <param name="campaignBudgetId">The campaign budget ID.</param>
        /// <returns>The string resource name for the newly created campaign.</returns>
        private string CreateCampaign(GoogleAdsClient client, long customerId,
                                      long merchantCenterAccountId, long campaignBudgetId)
        {
            // Creates the Campaign Service client.
            CampaignServiceClient campaignServiceClient =
                client.GetService(Services.V6.CampaignService);

            string budgetResourceName = ResourceNames.CampaignBudget(customerId, campaignBudgetId);

            // Creates the campaign.
            Campaign campaign = new Campaign()
            {
                Name = "Shopping campaign #" + ExampleUtilities.GetRandomString(),
                // Dynamic remarketing campaigns are only available on the Google Display Network.
                AdvertisingChannelType = AdvertisingChannelType.Display,
                Status         = CampaignStatus.Paused,
                CampaignBudget = budgetResourceName,
                ManualCpc      = new ManualCpc(),
                // The settings for the shopping campaign.
                // This connects the campaign to the Merchant Center account.
                ShoppingSetting = new Campaign.Types.ShoppingSetting()
                {
                    CampaignPriority = 0,
                    MerchantId       = merchantCenterAccountId,
                    // Display Network campaigns do not support partition by country. The only
                    // supported value is "ZZ". This signals that products from all countries are
                    // available in the campaign. The actual products which serve are based on
                    // the products tagged in the user list entry.
                    SalesCountry = "ZZ",
                    EnableLocal  = true
                }
            };

            // Creates the campaign operation.
            CampaignOperation operation = new CampaignOperation()
            {
                Create = campaign
            };

            // Adds the campaign.
            MutateCampaignsResponse response = campaignServiceClient.MutateCampaigns(customerId
                                                                                     .ToString(), new[] { operation });
            string campaignResourceName = response.Results.First().ResourceName;

            Console.WriteLine($"Created campaign with resource name '{campaignResourceName}'.");
            return(campaignResourceName);
        }
Пример #22
0
        public static void getCampaignByCampaignId()
        {
            CampaignServiceClient client = new CampaignServiceClient();

            AuthHeader authHeader = new AuthHeader();

            HeaderUtil.loadHeader(authHeader);

            long[] parameters = new long[1];
            parameters[0] = 984751L;

            CampaignType[] result    = null;
            ResHeader      resHeader = client.getCampaignByCampaignId(authHeader, parameters, out result);

            Console.WriteLine("CampaignService.getCampaignByCampaignId(): ");
            ObjectDumper.WriteResponse(resHeader, result);
        }
Пример #23
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="campaignId">ID of the campaign to be updated.</param>
        public void Run(GoogleAdsClient client, long customerId, long campaignId)
        {
            // Get the CampaignService.
            CampaignServiceClient campaignService = client.GetService(Services.V6.CampaignService);

            // Update campaign by setting its status to paused, and "Search network" to false.
            Campaign campaignToUpdate = new Campaign()
            {
                ResourceName    = ResourceNames.Campaign(customerId, campaignId),
                Status          = CampaignStatus.Paused,
                NetworkSettings = new NetworkSettings()
                {
                    TargetSearchNetwork = false
                }
            };

            // Create the operation.
            CampaignOperation operation = new CampaignOperation()
            {
                Update     = campaignToUpdate,
                UpdateMask = FieldMasks.AllSetFieldsOf(campaignToUpdate)
            };

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

                // Display the results.
                foreach (MutateCampaignResult updatedCampaign in response.Results)
                {
                    Console.WriteLine($"Campaign with resource ID = " +
                                      $"'{updatedCampaign.ResourceName}' was updated.");
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
Пример #24
0
        /// <summary>Snippet for MutateCampaignsAsync</summary>
        public async Task MutateCampaignsAsync()
        {
            // Snippet: MutateCampaignsAsync(string, IEnumerable<CampaignOperation>, CallSettings)
            // Additional: MutateCampaignsAsync(string, IEnumerable<CampaignOperation>, CancellationToken)
            // Create client
            CampaignServiceClient campaignServiceClient = await CampaignServiceClient.CreateAsync();

            // Initialize request argument(s)
            string customerId = "";
            IEnumerable <CampaignOperation> operations = new CampaignOperation[]
            {
                new CampaignOperation(),
            };
            // Make the request
            MutateCampaignsResponse response = await campaignServiceClient.MutateCampaignsAsync(customerId, operations);

            // End snippet
        }
        /// <summary>
        /// Adds a 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="budgetResourceName">The campaign budget resource name.</param>
        /// <returns>The campaign resource name.</returns>
        private static string AddCampaign(GoogleAdsClient client, long customerId,
                                          string budgetResourceName)
        {
            // Get the CampaignService.
            CampaignServiceClient campaignService = client.GetService(Services.V4.CampaignService);

            // Create the campaign.
            Campaign campaign = new Campaign()
            {
                Name = "Interplanetary Cruise #" + ExampleUtilities.GetRandomString(),
                AdvertisingChannelType = AdvertisingChannelType.Search,
                Status         = CampaignStatus.Paused,
                ManualCpc      = new ManualCpc(),
                CampaignBudget = budgetResourceName,

                // Enable the campaign for DSAs.
                DynamicSearchAdsSetting = new DynamicSearchAdsSetting()
                {
                    DomainName   = "example.com",
                    LanguageCode = "en"
                },

                StartDate = DateTime.Now.AddDays(1).ToString("yyyyMMdd"),
                EndDate   = DateTime.Now.AddDays(30).ToString("yyyyMMdd")
            };

            // Create the operation.
            CampaignOperation operation = new CampaignOperation()
            {
                Create = campaign
            };

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

            // Displays the result.
            string campaignResourceName = response.Results[0].ResourceName;

            Console.WriteLine($"Added campaign with resource name '{campaignResourceName}'.");
            return(campaignResourceName);
        }
Пример #26
0
 /// <summary>Snippet for MutateCampaigns</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void MutateCampaignsRequestObject()
 {
     // Create client
     CampaignServiceClient campaignServiceClient = CampaignServiceClient.Create();
     // Initialize request argument(s)
     MutateCampaignsRequest request = new MutateCampaignsRequest
     {
         CustomerId = "",
         Operations =
         {
             new CampaignOperation(),
         },
         PartialFailure      = false,
         ValidateOnly        = false,
         ResponseContentType = ResponseContentTypeEnum.Types.ResponseContentType.Unspecified,
     };
     // Make the request
     MutateCampaignsResponse response = campaignServiceClient.MutateCampaigns(request);
 }
Пример #27
0
        /// <summary>Snippet for MutateCampaignsAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task MutateCampaignsRequestObjectAsync()
        {
            // Create client
            CampaignServiceClient campaignServiceClient = await CampaignServiceClient.CreateAsync();

            // Initialize request argument(s)
            MutateCampaignsRequest request = new MutateCampaignsRequest
            {
                CustomerId = "",
                Operations =
                {
                    new CampaignOperation(),
                },
                PartialFailure = false,
                ValidateOnly   = false,
            };
            // Make the request
            MutateCampaignsResponse response = await campaignServiceClient.MutateCampaignsAsync(request);
        }
Пример #28
0
 /// <summary>Snippet for MutateCampaigns</summary>
 public void MutateCampaignsRequestObject()
 {
     // Snippet: MutateCampaigns(MutateCampaignsRequest, CallSettings)
     // Create client
     CampaignServiceClient campaignServiceClient = CampaignServiceClient.Create();
     // Initialize request argument(s)
     MutateCampaignsRequest request = new MutateCampaignsRequest
     {
         CustomerId = "",
         Operations =
         {
             new CampaignOperation(),
         },
         PartialFailure = false,
         ValidateOnly   = false,
     };
     // Make the request
     MutateCampaignsResponse response = campaignServiceClient.MutateCampaigns(request);
     // End snippet
 }
Пример #29
0
        public static void updateCampaign()
        {
            CampaignServiceClient client = new CampaignServiceClient();

            AuthHeader authHeader = new AuthHeader();

            HeaderUtil.loadHeader(authHeader);

            CampaignType[] parameters = new CampaignType[1];
            parameters[0]                     = new CampaignType();
            parameters[0].campaignId          = 984751L;
            parameters[0].campaignIdSpecified = true;
            parameters[0].campaignName        = "Demo_" + DateTime.Now.Ticks % 1000000;
            parameters[0].status              = 1;
            parameters[0].statusSpecified     = true;

            long[]    result    = null;
            ResHeader resHeader = client.updateCampaign(authHeader, ref parameters);

            Console.WriteLine("CampaignService.updateCampaign(): ");
            ObjectDumper.WriteResponse(resHeader, result);
        }
Пример #30
0
        /// <summary>Snippet for MutateCampaignsAsync</summary>
        public async Task MutateCampaignsRequestObjectAsync()
        {
            // Snippet: MutateCampaignsAsync(MutateCampaignsRequest, CallSettings)
            // Additional: MutateCampaignsAsync(MutateCampaignsRequest, CancellationToken)
            // Create client
            CampaignServiceClient campaignServiceClient = await CampaignServiceClient.CreateAsync();

            // Initialize request argument(s)
            MutateCampaignsRequest request = new MutateCampaignsRequest
            {
                CustomerId = "",
                Operations =
                {
                    new CampaignOperation(),
                },
                PartialFailure = false,
                ValidateOnly   = false,
            };
            // Make the request
            MutateCampaignsResponse response = await campaignServiceClient.MutateCampaignsAsync(request);

            // End snippet
        }
Пример #31
0
        /// <summary>
        /// Updates a campaign to set the DSA feed.
        /// </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="feedResourceName">The DSA feed resource name</param>
        /// <param name="campaignId">ID of the campaign for which DSA settings are updated.</param>
        private void UpdateCampaignDsaSetting(GoogleAdsClient client, long customerId,
                                              string feedResourceName, long campaignId)
        {
            // Get the CampaignService.
            CampaignServiceClient campaignService = client.GetService(
                Services.V3.CampaignService);

            DynamicSearchAdsSetting dsaSetting = GetDsaSetting(client, customerId, campaignId);

            dsaSetting.Feeds.Add(feedResourceName);

            // Create the campaign.
            Campaign campaign = new Campaign()
            {
                ResourceName            = ResourceNames.Campaign(customerId, campaignId),
                DynamicSearchAdsSetting = dsaSetting
            };

            // Create the operation.
            CampaignOperation operation = new CampaignOperation()
            {
                Update     = campaign,
                UpdateMask = FieldMasks.AllSetFieldsOf(campaign)
            };

            // Update the campaign.
            MutateCampaignsResponse response =
                campaignService.MutateCampaigns(customerId.ToString(), new[] { operation });

            // Display the results.
            foreach (MutateCampaignResult mutateCampaignResult in response.Results)
            {
                Console.WriteLine($"Updated campaign with resourceName: " +
                                  $"'{mutateCampaignResult.ResourceName}'.");
            }
        }