Ejemplo n.º 1
0
        /// <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);

            ExpressBusiness business1 = new ExpressBusiness();

            business1.status = ExpressBusinessStatus.ENABLED;
            business1.name   = "Express Interplanetary Cruise #" + ExampleUtilities.GetShortRandomString();

            Address address1 = new Address();

            address1.streetAddress = "1600 Amphitheatre Pkwy";
            address1.cityName      = "Mountain View";
            address1.provinceCode  = "CA";
            address1.countryCode   = "US";

            business1.address = address1;
            business1.website = "http://www.example.com/cruise1";

            ExpressBusinessOperation operation1 = new ExpressBusinessOperation();

            operation1.@operator = Operator.ADD;
            operation1.operand   = business1;

            ExpressBusiness business2 = new ExpressBusiness();

            business2.status = (ExpressBusinessStatus.ENABLED);
            business2.name   = "Express Interplanetary Cruise #" + ExampleUtilities.GetShortRandomString();

            Address address2 = new Address();

            address2.streetAddress = "111 8th Ave";
            address2.cityName      = "New York";
            address2.provinceCode  = "NY";
            address2.countryCode   = "US";

            business2.address = address2;
            business2.website = "http://www.example.com/cruise2";

            ExpressBusinessOperation operation2 = new ExpressBusinessOperation();

            operation2.@operator = Operator.ADD;
            operation2.operand   = business2;

            try {
                ExpressBusiness[] addedBusinesses = businessService.mutate(
                    new ExpressBusinessOperation[] { operation1, operation2 });

                Console.WriteLine("Added {0} express businesses", addedBusinesses.Length);
                foreach (ExpressBusiness addedBusiness in addedBusinesses)
                {
                    Console.WriteLine("Added express business with ID = {0} and name '{1}'.",
                                      addedBusiness.id, addedBusiness.name);
                }
            } catch (Exception ex) {
                throw new System.ApplicationException("Failed to add express business.", ex);
            }
        }
Ejemplo 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 ExpressBusinessService.
            ExpressBusinessService businessService = (ExpressBusinessService)
                                                     user.GetService(AdWordsService.v201601.ExpressBusinessService);

            // Update the website and address for the business
            ExpressBusiness business = new ExpressBusiness();

            business.id      = businessId;
            business.name    = "Express Interplanetary Cruise #" + ExampleUtilities.GetShortRandomString();
            business.website = "http://www.example.com/?myParam=" + businessId;

            ExpressBusinessOperation operation = new ExpressBusinessOperation();

            operation.@operator = Operator.SET;
            operation.operand   = business;

            try {
                ExpressBusiness[] updatedBusinesses =
                    businessService.mutate(new ExpressBusinessOperation[] { operation });

                Console.WriteLine("Express business with ID {0} and name '{1}' was updated.",
                                  updatedBusinesses[0].id, updatedBusinesses[0].name);
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to update express business.", e);
            }
        }
        /// <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>
        public void Run(AdWordsUser user)
        {
            // Get the ExpressBusinessService.
            ExpressBusinessService businessService = (ExpressBusinessService)
                                                     user.GetService(AdWordsService.v201605.ExpressBusinessService);

            ExpressBusiness business1 = new ExpressBusiness();

            business1.status  = ExpressBusinessStatus.ENABLED;
            business1.name    = "Express Interplanetary Cruise #" + ExampleUtilities.GetShortRandomString();
            business1.website = "http://www.example.com/cruise1";

            ExpressBusinessOperation operation1 = new ExpressBusinessOperation();

            operation1.@operator = Operator.ADD;
            operation1.operand   = business1;

            ExpressBusiness business2 = new ExpressBusiness();

            business2.status  = (ExpressBusinessStatus.ENABLED);
            business2.name    = "Express Interplanetary Cruise #" + ExampleUtilities.GetShortRandomString();
            business2.website = "http://www.example.com/cruise2";

            ExpressBusinessOperation operation2 = new ExpressBusinessOperation();

            operation2.@operator = Operator.ADD;
            operation2.operand   = business2;

            try {
                ExpressBusiness[] addedBusinesses = businessService.mutate(
                    new ExpressBusinessOperation[] { operation1, operation2 });

                Console.WriteLine("Added {0} express businesses", addedBusinesses.Length);
                foreach (ExpressBusiness addedBusiness in addedBusinesses)
                {
                    Console.WriteLine("Added express business with ID = {0} and name '{1}'.",
                                      addedBusiness.id, addedBusiness.name);
                }
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to add express business.", e);
            }
        }
Ejemplo n.º 6
0
        /// <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.v201506.ExpressBusinessService);

            // Get the PromotionService
            PromotionService promotionService = (PromotionService)
                                                user.GetService(AdWordsService.v201506.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);
            }
        }
Ejemplo n.º 7
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 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);
            }
        }