Ejemplo n.º 1
0
    public long CreateBudget(AdWordsUser user) {
      BudgetService budgetService =
          (BudgetService) user.GetService(AdWordsService.v201506.BudgetService);

      // Create the campaign budget.
      Budget budget = new Budget();
      budget.name = "Interplanetary Cruise Budget #" + DateTime.Now.ToString(
          "yyyy-M-d H:m:s.ffffff");
      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;

      BudgetReturnValue budgetRetval = budgetService.mutate(new BudgetOperation[] { budgetOperation });
      return budgetRetval.value[0].budgetId;
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Runs the code example.
    /// </summary>
    /// <param name="user">The AdWords user.</param>
    public void Run(AdWordsUser user) {
      // Get the CampaignService.
      BudgetService budgetService =
          (BudgetService) user.GetService(AdWordsService.v201506.BudgetService);

      // Get the CampaignService.
      CampaignService campaignService =
          (CampaignService) user.GetService(AdWordsService.v201506.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_CPM;

        // Optional: also provide matching bidding scheme.
        biddingConfig.biddingScheme = new ManualCpmBiddingScheme();

        campaign.biddingStrategyConfiguration = biddingConfig;

        // Set the campaign budget.
        campaign.budget = new Budget();
        campaign.budget.budgetId = budget.budgetId;

        // Set targetContentNetwork true. Other network targeting is not available
        // for Ad Exchange Buyers.
        campaign.networkSetting = new NetworkSetting();
        campaign.networkSetting.targetGoogleSearch = false;
        campaign.networkSetting.targetSearchNetwork = false;
        campaign.networkSetting.targetContentNetwork = true;
        campaign.networkSetting.targetPartnerSearchNetwork = false;

        // Enable campaign for Real-time bidding.
        RealTimeBiddingSetting rtbSetting = new RealTimeBiddingSetting();
        rtbSetting.optIn = true;

        campaign.settings = new Setting[] {rtbSetting};

        // 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);
      }
    }
Ejemplo n.º 3
0
    public void TestGetAllCampaignsMockAndCallServer() {
      ServiceSignature mockSignature = MockUtilities.RegisterMockService(user,
          AdWordsService.v201506.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);
    }
    /// <summary>
    /// Creates an explicit budget to be used only to create the Campaign.
    /// </summary>
    /// <param name="budgetService">The budget service.</param>
    /// <param name="name">The budget name.</param>
    /// <param name="amount">The budget amount.</param>
    /// <returns>The budget object.</returns>
    private Budget CreateSharedBudget(BudgetService budgetService, String name, long amount) {
      // Create a shared budget
      Budget budget = new Budget();
      budget.name = name;
      budget.period = BudgetBudgetPeriod.DAILY;
      budget.amount = new Money();
      budget.amount.microAmount = amount;
      budget.deliveryMethod = BudgetBudgetDeliveryMethod.STANDARD;
      budget.isExplicitlyShared = true;

      // Create operation.
      BudgetOperation operation = new BudgetOperation();
      operation.operand = budget;
      operation.@operator = Operator.ADD;

      // Make the mutate request.
      return budgetService.mutate(new BudgetOperation[] {operation}).value[0];
    }