示例#1
0
        private static void FoodDetailsExample()
        {
            // Get the food id, call the service, show the response.

            var foodId = AskFor <int>("Enter a food id: ");

            if (foodDetail == null)
            {
                foodDetail = new FoodDetails(consumerKey, consumerSecret);
            }

            var response = foodDetail
                           .GetResponseSynchronously(
                new FoodDetailsRequest()
            {
                FoodId = foodId
            });

            if (response.HasResponse)
            {
                Console.WriteLine("Found " + response.food.servings.serving.Count + " Results: ");

                foreach (var serv in response.food.servings.serving)
                {
                    // Use a little reflection to help show the results.
                    ShowPropertyValues(serv);
                }
            }
            else
            {
                Console.WriteLine("No response for food id: " + foodId);
            }
        }
        public MultiFoodServingsDetails GetFood(int id)
        {
            var fooditem    = new FoodDetails(_consumerKey, _consumerSecret);
            var itemrequest = new FoodDetailsRequest {
                FoodId = id
            };
            var response = fooditem.GetResponseSynchronously(itemrequest);

            if (response != null && response.HasResponse)
            {
                return(response.food);
            }
            return(null);
        }