How to use Bing Search Api using C #

I would like to use Cognitive Services to use the Bing Search APIs . I created a Cog Services account in Azure Portal and used the key specified in the properties in my sample application. There are 2 keys that are listed.

A few questions:

  • Which of these keys is used by us?
  • Do I also need to set the Ocp-Apim-Subscription-Key in the header?
  • I will be able to deny access and wonder if there is anything else that is missing when setting up cognitive services on Azure Portal.
  • Am I confused if I should use Bing Api or Cognitive Services? Are both the same?
  • Maybe someone can share a very simple example, since the one below (although very simple) does not work.

An example of a simplified code snippet to show what I'm doing:

...

string searchApiUrl = String.Format(
                "https://api.cognitive.microsoft.com/bing/v5.0/news/search?q={0}&AccountKey={1}",
                WebUtility.HtmlEncode("Movies"),
                "MY ACCOUNT ID FROM Azure PORTAL");

HttpClient httpClient = new HttpClient();
string response1 = await httpClient.GetStringAsync(searchApiUrl);

...

+4
source share
1 answer
  • If you use a free subscription, you will have 2 keys listed in the subscription list. You have a primary and backup key, and both will work.
  • Yes, Ocp-Apim-Subscription-Key is required in the header.
  • Most likely, this is due to the wrong key (or absence).
  • Yes, the Bing Search API falls under the Umbrella Cognitive Services.
  • , .
+2

Source: https://habr.com/ru/post/1649339/


All Articles