khar
khar

Reputation: 201

How to use Bing Search Api using c#

I'd like to use Cognitive Services to use Bing Search APIs. I created Cog Services Account in Azure Portal and used the key listed in properties in my sample app. There are 2 keys which are listed

Few questions:

  1. Which of these keys is the one which we should use?
  2. Do we also need to set Ocp-Apim-Subscription-Key in the header?
  3. I am hitting access denied and wondering if there is anything else which is missing in configuring Cognitive services in Azure Portal.
  4. I am confused if I should be using Bing Api or Cognitive Services? Are both these the same thing?
  5. Can someone please share very basic example as the one I have below (though very simple) doesn't work.

example simplistic code snippet to show what I am 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);

...

Upvotes: 4

Views: 2911

Answers (1)

Ray501s
Ray501s

Reputation: 46

  1. If you are using the free subscription, you will have 2 keys listed in your subscription list. You have a primary and a backup Key, and both will work.
  2. Yes, Ocp-Apim-Subscription-Key is required in the header.
  3. This is most likely related to incorrect key (or missing).
  4. Yes, the Bing Search API falls under the Cognitive Services Umbrella.
  5. There is a testing console available here, along with code samples on the bottom of the page.

Upvotes: 2

Related Questions