public async static Task GetTreadingNewsAsync(IDialogContext context, string key) { INewsSearchAPI client = new NewsSearchAPI(new Microsoft.Azure.CognitiveServices.Search.NewsSearch.ApiKeyServiceClientCredentials(key)); var result = await client.News.TrendingAsync(count : 3); if (result?.Value?.Count > 0) { await context.PostAsync($"Here is top 5 Treading News"); var message = context.MakeMessage(); message.AttachmentLayout = AttachmentLayoutTypes.Carousel; foreach (var item in result.Value) { HeroCard card = new HeroCard { Title = item.Name, Images = new List <CardImage> { new CardImage(item.Image.Url) }, Buttons = new List <CardAction> { new CardAction(ActionTypes.OpenUrl, "Read More", value: item.Url) } }; message.Attachments.Add(card.ToAttachment()); } await context.PostAsync(message); } }
public static void NewsCategory(string subscriptionKey) { var client = new NewsSearchAPI(new ApiKeyServiceClientCredentials(subscriptionKey)); try { var newsResults = client.News.CategoryAsync(category: "Entertainment_MovieAndTV", market: "en-us", safeSearch: "strict").Result; Console.WriteLine("Search category news for movie and TV entertainment with safe search"); if (newsResults == null) { Console.WriteLine("Didn't see any news result data.."); } else { if (newsResults.Value.Count > 0) { var firstNewsResult = newsResults.Value.First(); Console.WriteLine($"News result count: {newsResults.Value.Count}"); Console.WriteLine($"First news category: {firstNewsResult.Category}"); Console.WriteLine($"First news name: {firstNewsResult.Name}"); Console.WriteLine($"First news url: {firstNewsResult.Url}"); Console.WriteLine($"First news description: {firstNewsResult.Description}"); Console.WriteLine($"First news published time: {firstNewsResult.DatePublished}"); Console.WriteLine($"First news provider: {firstNewsResult.Provider.First().Name}"); } else { Console.WriteLine("Couldn't find news results!"); } } } catch (Exception ex) { Console.WriteLine("Encountered exception. " + ex.Message); } }
public static void NewsSearchWithFilters(string subscriptionKey) { var client = new NewsSearchAPI(new ApiKeyServiceClientCredentials(subscriptionKey)); try { var newsResults = client.News.SearchAsync(query: "Artificial Intelligence", market: "en-us", freshness: "Week", sortBy: "Date").Result; Console.WriteLine("Search most recent news for query \"Artificial Intelligence\" with freshness and sortBy"); if (newsResults == null) { Console.WriteLine("Didn't see any news result data.."); } else { if (newsResults.Value.Count > 0) { var firstNewsResult = newsResults.Value.First(); Console.WriteLine($"TotalEstimatedMatches value: {newsResults.TotalEstimatedMatches}"); Console.WriteLine($"News result count: {newsResults.Value.Count}"); Console.WriteLine($"First news name: {firstNewsResult.Name}"); Console.WriteLine($"First news url: {firstNewsResult.Url}"); Console.WriteLine($"First news description: {firstNewsResult.Description}"); Console.WriteLine($"First news published time: {firstNewsResult.DatePublished}"); Console.WriteLine($"First news provider: {firstNewsResult.Provider.First().Name}"); } else { Console.WriteLine("Couldn't find news results!"); } } } catch (Exception ex) { Console.WriteLine("Encountered exception. " + ex.Message); } }
public static void NewsSearch(string subscriptionKey) { var client = new NewsSearchAPI(new ApiKeyServiceClientCredentials(subscriptionKey)); try { var newsResults = client.News.SearchAsync(query: "Quantum Computing", market: "en-us", count: 10).Result; Console.WriteLine("Search news for query \"Quantum Computing\" with market and count"); if (newsResults == null) { Console.WriteLine("Didn't see any news result data.."); } else { if (newsResults.Value.Count > 0) { var firstNewsResult = newsResults.Value.First(); Console.WriteLine($"TotalEstimatedMatches value: {newsResults.TotalEstimatedMatches}"); Console.WriteLine($"News result count: {newsResults.Value.Count}"); Console.WriteLine($"First news name: {firstNewsResult.Name}"); Console.WriteLine($"First news url: {firstNewsResult.Url}"); Console.WriteLine($"First news description: {firstNewsResult.Description}"); Console.WriteLine($"First news published time: {firstNewsResult.DatePublished}"); Console.WriteLine($"First news provider: {firstNewsResult.Provider.First().Name}"); } else { Console.WriteLine("Couldn't find news results!"); } } } catch (Exception ex) { Console.WriteLine("Encountered exception. " + ex.Message); } }
public static void TrendingTopics(string subscriptionKey) { var client = new NewsSearchAPI(new ApiKeyServiceClientCredentials(subscriptionKey)); try { var trendingTopics = client.News.TrendingAsync(market: "en-us").Result; Console.WriteLine("Search news trending topics in Bing"); if (trendingTopics == null) { Console.WriteLine("Didn't see any news trending topics.."); } else { if (trendingTopics.Value.Count > 0) { var firstTopic = trendingTopics.Value.First(); Console.WriteLine($"Trending topics count: {trendingTopics.Value.Count}"); Console.WriteLine($"First topic name: {firstTopic.Name}"); Console.WriteLine($"First topic query: {firstTopic.Query.Text}"); Console.WriteLine($"First topic image url: {firstTopic.Image.Url}"); Console.WriteLine($"First topic webSearchUrl: {firstTopic.WebSearchUrl}"); Console.WriteLine($"First topic newsSearchUrl: {firstTopic.NewsSearchUrl}"); } else { Console.WriteLine("Couldn't find news trending topics!"); } } } catch (Exception ex) { Console.WriteLine("Encountered exception. " + ex.Message); } }