/// <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.v201402.ExpressBusinessService); // Get the PromotionService PromotionService promotionService = (PromotionService) user.GetService(AdWordsService.v201402.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(); operation.@operator = 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 ex) { throw new System.ApplicationException("Failed to update promotions.", ex); } }
/// <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.v201402.ExpressBusinessService); // Get the PromotionService PromotionService promotionService = (PromotionService) user.GetService(AdWordsService.v201402.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(); Predicate predicate = new Predicate(); predicate.field = "Id"; predicate.@operator = PredicateOperator.EQUALS; predicate.values = new string[] { businessId.ToString() }; businessSelector.predicates = new Predicate[] { predicate }; businessSelector.fields = new string[] { "Id", "GeoPoint" }; 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 }; // Creatives Creative creative1 = new Creative(); creative1.headline = "Standard Mars Trip"; creative1.line1 = "Fly coach to Mars"; creative1.line2 = "Free in-flight pretzels"; Creative creative2 = new Creative(); creative2.headline = "Deluxe Mars Trip"; creative2.line1 = "Fly first class to Mars"; creative2.line2 = "Unlimited powdered orange drink"; marsTourPromotion.creatives = new Creative[] { creative1, creative2 }; PromotionOperation operation = new PromotionOperation(); operation.@operator = 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 ex) { throw new System.ApplicationException("Failed to add promotions.", ex); } }
/// <summary> /// Formats a money value for display purposes. /// </summary> /// <param name="m">The money value.</param> /// <returns>The formatted money value as text.</returns> private static String Dashify(Money m) { return m == null ? "--" : m.microAmount.ToString(); }