/// <summary> /// Function to get autosuggestions, based on given queries. Uses the autosuggest endpoint /// </summary> /// <param name="query">Query string to generate auto suggestions from</param> /// <returns>List of suggested words</returns> public async Task <List <string> > Suggest(string query) { string endpoint = string.Format("{0}{1}&mkt=en-US", "https://api.cognitive.microsoft.com/bing/v7.0/suggestions/?q=", query); List <string> suggestionResult = new List <string>(); try { BingAutoSuggestResponse response = await _webRequest.MakeRequest <BingAutoSuggestResponse>(endpoint); if (response == null || response.suggestionGroups.Length == 0) { return(suggestionResult); } foreach (Suggestiongroup suggestionGroup in response.suggestionGroups) { foreach (Searchsuggestion suggestion in suggestionGroup.searchSuggestions) { suggestionResult.Add(suggestion.displayText); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); } return(suggestionResult); }
/// <summary> /// Function to search for images. Uses an endpoint for image search /// </summary> /// <param name="query">The query to search for</param> /// <returns>The <see cref="ImageSearchResponse"/>, containing image details</returns> public async Task <ImageSearchResponse> SearchImages(string query) { string endpoint = string.Format("{0}{1}", "https://api.cognitive.microsoft.com/bing/v5.0/images/search?q=", query); try { ImageSearchResponse response = await _webRequest.MakeRequest <ImageSearchResponse>(endpoint); return(response); } catch (Exception ex) { Debug.WriteLine(ex.Message); } return(null); }