/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign to be removed.</param> public void Run(AdWordsUser user, long campaignId) { // Get the CampaignService. CampaignService campaignService = (CampaignService) user.GetService( AdWordsService.v201409.CampaignService); // Create campaign with REMOVED status. Campaign campaign = new Campaign(); campaign.id = campaignId; campaign.status = CampaignStatus.REMOVED; // Create the operation. CampaignOperation operation = new CampaignOperation(); operation.operand = campaign; operation.@operator = Operator.SET; try { // Remove the campaign. CampaignReturnValue retVal = campaignService.mutate(new CampaignOperation[] {operation}); // Display the results. if (retVal != null && retVal.value != null && retVal.value.Length > 0) { Campaign removedCampaign = retVal.value[0]; Console.WriteLine("Campaign with id = \"{0}\" was renamed to \"{1}\" and removed.", removedCampaign.id, removedCampaign.name); } else { Console.WriteLine("No campaigns were removed."); } } catch (Exception ex) { throw new System.ApplicationException("Failed to remove campaign.", ex); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign to be updated.</param> public void Run(AdWordsUser user, long campaignId) { // Get the CampaignService. CampaignService campaignService = (CampaignService)user.GetService(AdWordsService.v201409.CampaignService); // Create the campaign. Campaign campaign = new Campaign(); campaign.id = campaignId; campaign.status = CampaignStatus.PAUSED; // Create the operation. CampaignOperation operation = new CampaignOperation(); operation.@operator = Operator.SET; operation.operand = campaign; try { // Update the campaign. CampaignReturnValue retVal = campaignService.mutate((new CampaignOperation[] {operation})); // Display the results. if (retVal != null && retVal.value != null && retVal.value.Length > 0) { Campaign updatedCampaign = retVal.value[0]; Console.WriteLine("Campaign with name = '{0}' and id = '{1}' was updated.", updatedCampaign.name, updatedCampaign.id); } else { Console.WriteLine("No campaigns were updated."); } } catch (Exception ex) { throw new System.ApplicationException("Failed to update campaign.", ex); } }
/// <summary> /// Creates the campaign with a shared bidding strategy. /// </summary> /// <param name="campaignService">The campaign service.</param> /// <param name="name">The campaign name.</param> /// <param name="biddingStrategyId">The bidding strategy id.</param> /// <param name="sharedBudgetId">The shared budget id.</param> /// <returns>The campaign object.</returns> private Campaign CreateCampaignWithBiddingStrategy(CampaignService campaignService, string name, long biddingStrategyId, long sharedBudgetId) { // Create campaign. Campaign campaign = new Campaign(); campaign.name = name; campaign.advertisingChannelType = AdvertisingChannelType.SEARCH; // Set the budget. campaign.budget = new Budget(); campaign.budget.budgetId = sharedBudgetId; // Set bidding strategy (required). BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration(); biddingStrategyConfiguration.biddingStrategyId = biddingStrategyId; campaign.biddingStrategyConfiguration = biddingStrategyConfiguration; // Set network targeting (recommended). NetworkSetting networkSetting = new NetworkSetting(); networkSetting.targetGoogleSearch = true; networkSetting.targetSearchNetwork = true; networkSetting.targetContentNetwork = true; campaign.networkSetting = networkSetting; // Create operation. CampaignOperation operation = new CampaignOperation(); operation.operand = campaign; operation.@operator = Operator.ADD; return campaignService.mutate(new CampaignOperation[] {operation}).value[0]; }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the BudgetService. BudgetService budgetService = (BudgetService) user.GetService(AdWordsService.v201409.BudgetService); // Get the CampaignService. CampaignService campaignService = (CampaignService) user.GetService(AdWordsService.v201409.CampaignService); // Create the campaign budget. Budget budget = new Budget(); budget.name = "Interplanetary Cruise Budget #" + ExampleUtilities.GetRandomString(); budget.period = BudgetBudgetPeriod.DAILY; budget.deliveryMethod = BudgetBudgetDeliveryMethod.STANDARD; budget.amount = new Money(); budget.amount.microAmount = 500000; BudgetOperation budgetOperation = new BudgetOperation(); budgetOperation.@operator = Operator.ADD; budgetOperation.operand = budget; try { BudgetReturnValue budgetRetval = budgetService.mutate(new BudgetOperation[] {budgetOperation}); budget = budgetRetval.value[0]; } catch (Exception ex) { throw new System.ApplicationException("Failed to add shared budget.", ex); } List<CampaignOperation> operations = new List<CampaignOperation>(); for (int i = 0; i < NUM_ITEMS; i++) { // Create the campaign. Campaign campaign = new Campaign(); campaign.name = "Interplanetary Cruise #" + ExampleUtilities.GetRandomString(); campaign.status = CampaignStatus.PAUSED; campaign.advertisingChannelType = AdvertisingChannelType.SEARCH; BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration(); biddingConfig.biddingStrategyType = BiddingStrategyType.MANUAL_CPC; campaign.biddingStrategyConfiguration = biddingConfig; campaign.budget = new Budget(); campaign.budget.budgetId = budget.budgetId; // Set the campaign network options. campaign.networkSetting = new NetworkSetting(); campaign.networkSetting.targetGoogleSearch = true; campaign.networkSetting.targetSearchNetwork = true; campaign.networkSetting.targetContentNetwork = false; campaign.networkSetting.targetPartnerSearchNetwork = false; // Set the campaign settings for Advanced location options. GeoTargetTypeSetting geoSetting = new GeoTargetTypeSetting(); geoSetting.positiveGeoTargetType = GeoTargetTypeSettingPositiveGeoTargetType.DONT_CARE; geoSetting.negativeGeoTargetType = GeoTargetTypeSettingNegativeGeoTargetType.DONT_CARE; campaign.settings = new Setting[] {geoSetting}; // Optional: Set the start date. campaign.startDate = DateTime.Now.AddDays(1).ToString("yyyyMMdd"); // Optional: Set the end date. campaign.endDate = DateTime.Now.AddYears(1).ToString("yyyyMMdd"); // Optional: Set the campaign ad serving optimization status. campaign.adServingOptimizationStatus = AdServingOptimizationStatus.ROTATE; // Optional: Set the frequency cap. FrequencyCap frequencyCap = new FrequencyCap(); frequencyCap.impressions = 5; frequencyCap.level = Level.ADGROUP; frequencyCap.timeUnit = TimeUnit.DAY; campaign.frequencyCap = frequencyCap; // Create the operation. CampaignOperation operation = new CampaignOperation(); operation.@operator = Operator.ADD; operation.operand = campaign; operations.Add(operation); } try { // Add the campaign. CampaignReturnValue retVal = campaignService.mutate(operations.ToArray()); // Display the results. if (retVal != null && retVal.value != null && retVal.value.Length > 0) { foreach (Campaign newCampaign in retVal.value) { Console.WriteLine("Campaign with name = '{0}' and id = '{1}' was added.", newCampaign.name, newCampaign.id); } } else { Console.WriteLine("No campaigns were added."); } } catch (Exception ex) { throw new System.ApplicationException("Failed to add campaigns.", ex); } }
public void TestGetAllCampaignsMockAndCallServer() { ServiceSignature mockSignature = MockUtilities.RegisterMockService(user, AdWordsService.v201409.CampaignService, typeof(MockCampaignServiceEx)); CampaignService campaignService = (CampaignService) user.GetService(mockSignature); Assert.That(campaignService is MockCampaignServiceEx); Campaign campaign = new Campaign(); campaign.name = "Interplanetary Cruise #" + new TestUtils().GetTimeStamp(); campaign.status = CampaignStatus.PAUSED; campaign.biddingStrategyConfiguration = new BiddingStrategyConfiguration(); campaign.biddingStrategyConfiguration.biddingStrategyType = BiddingStrategyType.MANUAL_CPC; Budget budget = new Budget(); budget.budgetId = budgetId; campaign.budget = budget; campaign.budget = budget; // Set the campaign network options to GoogleSearch and SearchNetwork // only. Set ContentNetwork, PartnerSearchNetwork and ContentContextual // to false. campaign.networkSetting = new NetworkSetting(); campaign.networkSetting.targetGoogleSearch = true; campaign.networkSetting.targetSearchNetwork = true; campaign.networkSetting.targetContentNetwork = false; campaign.networkSetting.targetPartnerSearchNetwork = false; // Create operations. CampaignOperation operation = new CampaignOperation(); operation.@operator = Operator.ADD; operation.operand = campaign; CampaignReturnValue retVal = null; Assert.DoesNotThrow(delegate() { retVal = campaignService.mutate((new CampaignOperation[] { operation })); }); Assert.NotNull(retVal); Assert.NotNull(retVal.value); Assert.AreEqual(retVal.value.Length, 1); Assert.AreEqual(retVal.value[0].name, campaign.name); Assert.AreNotEqual(retVal.value[0].id, 0); Assert.True((campaignService as MockCampaignServiceEx).MutateCalled); }