Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Streams and Data Processing Streaming Data on the Net Searching for News Headlines

Simon Sporrong
Simon Sporrong
35,097 Points

I made a new GetNewsForPlayer-method, following the new docs

So, if you are taking this course now (in 2019) the Microsoft docs that Carling is using is heavily outdated and is really cumbersome to use. So i followed the new updated docs and made a new GetNewsForplayer-method that works just fine and is easer to use since it doesn't require Streams and Readers.

The docs can be found here: https://docs.microsoft.com/sv-se/azure/cognitive-services/bing-News-search/news-search-sdk-quickstart

Note: You have to install the Azure.CognitiveServices.Search.NewsSearch package. Right click on your solution and select 'Manage NuGet Packages' and search for: Azure Cognitive News and select the Microsoft.Azure.CognitiveServices.Search.NewsSearch package. You must also use the namespace up top:

using Microsoft.Azure.CognitiveServices.Search.NewsSearch;

And the method

public static string GetNewsForPlayer(string playerName)
        {
            var key = YOUR_API_KEY
            var client = new NewsSearchClient(new ApiKeyServiceClientCredentials(key));
            var newsResults = client.News.SearchAsync(query: playerName, market: "en-us", count: 10).Result;
            if (newsResults.Value.Count > 0)
            {
                return newsResults.Value[0].Description;
            }
            else
            {
                return "No news found on this player";
            }

        }

The method can most certainly be enhanced but at least it does the job.

Hope that it can help someone!

I agree, it was difficult to use. I was able to find a way to get it working with the newer version but it took some tinkering. I suppose that's valuable experience though! Great job finding another work around.

Hugo Zaanen
Hugo Zaanen
11,897 Points

You need an account and get a subscription to get the API Key?

1 Answer

Simon Sporrong
Simon Sporrong
35,097 Points

Hugo Zaanen You don't need a subscription key for the NewsSearch but later in the course where we're using TextAnalytics you need a subscription in order to get the correct endpoint, key and region.