-
Notifications
You must be signed in to change notification settings - Fork 265
/
BingEntitySearchv7.cs
46 lines (34 loc) · 1.47 KB
/
BingEntitySearchv7.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using Newtonsoft.Json;
using System;
using System.Net.Http;
/* This sample makes a call to the Bing Entity Search v7 API with a query and returns details about it.
* Bing Entity Search API:
* https://westus2.dev.cognitive.microsoft.com/docs/services/7a3fb374be374859a823b79fd938cc65/operations/52069701a465405ab3286f82
*/
namespace BingEntitySearch
{
class Program
{
// Add your key and endpoint to your environment variables.
static string key = Environment.GetEnvironmentVariable("BING_ENTITY_SEARCH_SUBSCRIPTION_KEY");
static string endpoint = Environment.GetEnvironmentVariable("BING_ENTITY_SEARCH_ENDPOINT");
static string path = "/bing/v7.0/entities/";
static string market = "en-US";
static string query = "italian restaurant near me";
async static void Search()
{
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", key);
string uri = endpoint + path + "?mkt=" + market + "&q=" + System.Net.WebUtility.UrlEncode(query);
HttpResponseMessage response = await client.GetAsync(uri);
string contentString = await response.Content.ReadAsStringAsync();
dynamic parsedJson = JsonConvert.DeserializeObject(contentString);
Console.WriteLine(parsedJson);
}
static void Main(string[] args)
{
Search();
Console.ReadLine();
}
}
}