/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the ExpressBusinessService. ExpressBusinessService businessService = (ExpressBusinessService) user.GetService(AdWordsService.v201406.ExpressBusinessService); Selector selector = new Selector(); selector.fields = new String[] { "Id", "Name", "Website", "Address", "GeoPoint", "Status" }; // To get all express businesses owned by the current customer, // simply skip the call to selector.setPredicates below. Predicate predicate = new Predicate(); predicate.field = "Status"; predicate.@operator = PredicateOperator.EQUALS; predicate.values = new string[] { "ACTIVE" }; selector.predicates = new Predicate[] { predicate }; // Set the selector paging. selector.paging = new Paging(); int offset = 0; int pageSize = 500; ExpressBusinessPage page = null; try { do { selector.paging.startIndex = offset; selector.paging.numberResults = pageSize; // Get all businesses. page = businessService.get(selector); // Display the results. if (page != null && page.entries != null) { int i = offset; foreach (ExpressBusiness business in page.entries) { Console.WriteLine("{0}) Express business found with name '{1}', id = {2}, " + "website = {3} and status = {4}.\n", i + 1, business.name, business.id, business.website, business.status); Console.WriteLine("Address"); Console.WriteLine("======="); Console.WriteLine(FormatAddress(business.address)); Console.WriteLine("Co-ordinates: {0}\n", FormatGeopoint(business.geoPoint)); i++; } } offset += pageSize; } while (offset < page.totalNumEntries); Console.WriteLine("Number of businesses found: {0}", page.totalNumEntries); } catch (Exception ex) { throw new System.ApplicationException("Failed to retrieve express business.", ex); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the ExpressBusinessService. ExpressBusinessService businessService = (ExpressBusinessService) user.GetService(AdWordsService.v201502.ExpressBusinessService); Selector selector = new Selector() { fields = new String[] { ExpressBusiness.Fields.Id, ExpressBusiness.Fields.Name, ExpressBusiness.Fields.Website, ExpressBusiness.Fields.Address, ExpressBusiness.Fields.GeoPoint, ExpressBusiness.Fields.Status }, predicates = new Predicate[] { // To get all express businesses owned by the current customer, // simply skip the call to selector.setPredicates below. Predicate.Equals(ExpressBusiness.Fields.Status, ExpressBusinessStatus.ENABLED.ToString()) }, paging = Paging.Default }; ExpressBusinessPage page = null; try { do { // Get all businesses. page = businessService.get(selector); // Display the results. if (page != null && page.entries != null) { int i = selector.paging.startIndex; foreach (ExpressBusiness business in page.entries) { Console.WriteLine("{0}) Express business found with name '{1}', id = {2}, " + "website = {3} and status = {4}.\n", i + 1, business.name, business.id, business.website, business.status); Console.WriteLine("Address"); Console.WriteLine("======="); Console.WriteLine(FormatAddress(business.address)); Console.WriteLine("Co-ordinates: {0}\n", FormatGeopoint(business.geoPoint)); i++; } } selector.paging.IncreaseOffset(); } while (selector.paging.startIndex < page.totalNumEntries); Console.WriteLine("Number of businesses found: {0}", page.totalNumEntries); } catch (Exception e) { throw new System.ApplicationException("Failed to retrieve express business.", 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.v201409.ExpressBusinessService); // Get the PromotionService PromotionService promotionService = (PromotionService) user.GetService(AdWordsService.v201409.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 }; // 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(); 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); } }