/// <summary>
    /// Runs the code example.
    /// </summary>
    /// <param name="user">The AdWords user.</param>
    /// <param name="businessId">The AdWords Express business id.</param>
    /// <param name="promotionId">The promotion id.</param>
    public void Run(AdWordsUser user, long businessId, long promotionId) {
      // Get the ExpressBusinessService.
      ExpressBusinessService businessService = (ExpressBusinessService)
          user.GetService(AdWordsService.v201509.ExpressBusinessService);

      // Get the PromotionService
      PromotionService promotionService = (PromotionService)
          user.GetService(AdWordsService.v201509.PromotionService);

      // Set the business ID to the service.
      promotionService.RequestHeader.expressBusinessId = businessId;

      // Update the budget for the promotion
      Promotion promotion = new Promotion();
      promotion.id = promotionId;
      Money newBudget = new Money();
      newBudget.microAmount = 2000000;
      promotion.budget = newBudget;

      PromotionOperation operation = new PromotionOperation();
      [email protected] = Operator.SET;
      operation.operand = promotion;

      try {
        Promotion[] updatedPromotions = promotionService.mutate(
            new PromotionOperation[] { operation });

        Console.WriteLine("Promotion ID {0} for business ID {1} now has budget micro " +
            "amount {2}.", promotionId, businessId,
            updatedPromotions[0].budget.microAmount);
      } catch (Exception e) {
        throw new System.ApplicationException("Failed to update promotions.", e);
      }
    }
Exemplo n.º 2
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="businessId">The AdWords Express business id.</param>
        public void Run(AdWordsUser user, long businessId)
        {
            // Get the PromotionService
              PromotionService promotionService = (PromotionService)
              user.GetService(AdWordsService.v201601.PromotionService);

              // Set the business ID to the service.
              promotionService.RequestHeader.expressBusinessId = businessId;

              // First promotion
              Promotion marsTourPromotion = new Promotion();
              Money budget = new Money();
              budget.microAmount = 1000000L;
              marsTourPromotion.name = "Mars Tour Promotion " + ExampleUtilities.GetShortRandomString();
              marsTourPromotion.status = PromotionStatus.PAUSED;
              marsTourPromotion.destinationUrl = "http://www.example.com";
              marsTourPromotion.budget = budget;
              marsTourPromotion.callTrackingEnabled = true;

              // Criteria

              // Criterion - Travel Agency product service
              ProductService productService = new ProductService();
              productService.text = "Travel Agency";

              // Criterion - English language
              // The ID can be found in the documentation:
              // https://developers.google.com/adwords/api/docs/appendix/languagecodes
              Language language = new Language();
              language.id = 1000L;

              // Criterion - State of California
              Location location = new Location();
              location.id = 21137L;

              marsTourPromotion.criteria = new Criterion[] { productService, language, location };

              // Creative
              Creative creative = new Creative();
              creative.headline = "Standard Mars Trip";
              creative.line1 = "Fly coach to Mars";
              creative.line2 = "Free in-flight pretzels";

              marsTourPromotion.creatives = new Creative[] { creative };

              PromotionOperation operation = new PromotionOperation();
              [email protected] = Operator.ADD;
              operation.operand = marsTourPromotion;

              try {
            Promotion[] addedPromotions = promotionService.mutate(
            new PromotionOperation[] { operation });

            Console.WriteLine("Added promotion ID {0} with name {1} to business ID {2}.",
            addedPromotions[0].id, addedPromotions[0].name, businessId);
              } catch (Exception e) {
            throw new System.ApplicationException("Failed to add promotions.", e);
              }
        }
    /// <summary>
    /// Runs the code example.
    /// </summary>
    /// <param name="user">The AdWords user.</param>
    /// <param name="businessId">The AdWords Express business id.</param>
    public void Run(AdWordsUser user, long businessId) {
      // Get the ExpressBusinessService.
      ExpressBusinessService businessService = (ExpressBusinessService)
          user.GetService(AdWordsService.v201509.ExpressBusinessService);

      // Get the PromotionService
      PromotionService promotionService = (PromotionService)
          user.GetService(AdWordsService.v201509.PromotionService);

      // Get the business for the businessId. We will need its geo point to
      // create a Proximity criterion for the new Promotion.
      Selector businessSelector = new Selector() {
        fields = new string[] {
          ExpressBusiness.Fields.Id, ExpressBusiness.Fields.GeoPoint
        },
        predicates = new Predicate[] {
          Predicate.Equals(ExpressBusiness.Fields.Id, businessId.ToString())
        }
      };

      ExpressBusinessPage businessPage = businessService.get(businessSelector);

      if (businessPage == null || businessPage.entries == null ||
          businessPage.entries.Length == 0) {
        Console.WriteLine("No business was found.");
        return;
      }

      // Set the business ID to the service.
      promotionService.RequestHeader.expressBusinessId = businessId;

      // First promotion
      Promotion marsTourPromotion = new Promotion();
      Money budget = new Money();
      budget.microAmount = 1000000L;
      marsTourPromotion.name = "Mars Tour Promotion " + ExampleUtilities.GetShortRandomString();
      marsTourPromotion.status = PromotionStatus.PAUSED;
      marsTourPromotion.destinationUrl = "http://www.example.com";
      marsTourPromotion.budget = budget;
      marsTourPromotion.callTrackingEnabled = true;

      // Criteria

      // Criterion - Travel Agency product service
      ProductService productService = new ProductService();
      productService.text = "Travel Agency";

      // Criterion - English language
      // The ID can be found in the documentation:
      // https://developers.google.com/adwords/api/docs/appendix/languagecodes
      Language language = new Language();
      language.id = 1000L;

      // Criterion - Within 15 miles
      Proximity proximity = new Proximity();
      proximity.geoPoint = businessPage.entries[0].geoPoint;
      proximity.radiusDistanceUnits = ProximityDistanceUnits.MILES;
      proximity.radiusInUnits = 15;

      marsTourPromotion.criteria = new Criterion[] { productService, language, proximity };

      // Creative
      Creative creative = new Creative();
      creative.headline = "Standard Mars Trip";
      creative.line1 = "Fly coach to Mars";
      creative.line2 = "Free in-flight pretzels";

      marsTourPromotion.creatives = new Creative[] { creative };

      PromotionOperation operation = new PromotionOperation();
      [email protected] = Operator.ADD;
      operation.operand = marsTourPromotion;

      try {
        Promotion[] addedPromotions = promotionService.mutate(
            new PromotionOperation[] { operation });

        Console.WriteLine("Added promotion ID {0} with name {1} to business ID {2}.",
        addedPromotions[0].id, addedPromotions[0].name, businessId);
      } catch (Exception e) {
        throw new System.ApplicationException("Failed to add promotions.", e);
      }
    }