private static void FoodSearchExample() { var searchTerm = AskFor <string>("Enter a search term: "); if (foodSearch == null) { foodSearch = new FoodSearch(consumerKey, consumerSecret); } var response = foodSearch.GetResponseSynchronously(new FoodSearchRequest() { SearchExpression = searchTerm }); if (response.HasResults) { Console.WriteLine("Got " + response.foods.food.Count + " Results: \n\n"); var form = "id: {0}, \n - type: {1}, \n - name: {2}, \n - description: {3}"; foreach (var food in response.foods.food) { Console.WriteLine(String.Format(form, food.food_id, food.food_type, food.food_name, food.food_description)); } } else { Console.WriteLine("No results from term: " + searchTerm); } Console.WriteLine(""); Console.WriteLine(""); }
public List <FoodInfo> SearchFoods(string search) { var foodSearch = new FoodSearch(_consumerKey, _consumerSecret); var itemrequest = new FoodSearchRequest { SearchExpression = search }; var response = foodSearch.GetResponseSynchronously(itemrequest); if (response != null && response.HasResults) { return(response.foods.food); } return(null); }
public string SearchFood(string searchExpression) { try { consumerKey = "your consumer Key"; consumerSecret = "your consumer Secret "; var searchTerm = searchExpression; foodSearch = new FoodSearch(consumerKey, consumerSecret); var response = foodSearch.GetResponseSynchronously(new FoodSearchRequest() { SearchExpression = searchTerm, MaxResults = 50, PageNumber = 0 }); if (response != null && response.HasResults) { return(new JavaScriptSerializer().Serialize(response)); } else { return(null); } } catch (Exception ex) { return(ex.Message); } }