Skip to content

Commit 47c7fcc

Browse files
authored
Updated to match JSON changes in API
1 parent e52d155 commit 47c7fcc

File tree

1 file changed

+19
-31
lines changed

1 file changed

+19
-31
lines changed

dotnet/Search/BingCustomSearchv7.cs

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
//Copyright (c) Microsoft Corporation. All rights reserved.
2-
//Licensed under the MIT License.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
33
// <using>
44
using System;
55
using System.Net.Http;
66
using System.Web;
77
using Newtonsoft.Json;
88
// </using>
99

10-
namespace bing_custom_search_example_dotnet
10+
namespace BingCustomSearch
1111
{
1212
class Program
1313
{
@@ -19,12 +19,12 @@ static void Main(string[] args)
1919
var subscriptionKey = Environment.GetEnvironmentVariable("BING_CUSTOM_SEARCH_SUBSCRIPTION_KEY");
2020
var endpoint = Environment.GetEnvironmentVariable("BING_CUSTOM_SEARCH_ENDPOINT");
2121

22-
var customConfigId = "YOUR-CUSTOM-CONFIG-ID"; // you can also use "1"
23-
var searchTerm = args.Length > 0 ? args[0]: "microsoft";
22+
var customConfigId = Environment.GetEnvironmentVariable("BING_CUSTOM_CONFIG"); // you can also use "1"
23+
var searchTerm = args.Length > 0 ? args[0] : "microsoft";
2424
// </vars>
2525
// <url>
2626
// Use your Azure Bing Custom Search endpoint to create the full request URL.
27-
var url = endpoint + "/search?" + "q=" + searchTerm + "&customconfig=" + customConfigId;
27+
var url = endpoint + "/bingcustomsearch/v7.0/images/search?" + "q=" + searchTerm + "&customconfig=" + customConfigId;
2828
// </url>
2929
// <client>
3030
var client = new HttpClient();
@@ -36,48 +36,36 @@ static void Main(string[] args)
3636
BingCustomSearchResponse response = JsonConvert.DeserializeObject<BingCustomSearchResponse>(responseContent);
3737
// </sendRequest>
3838
// <iterateResponse>
39-
for(int i = 0; i < response.webPages.value.Length; i++)
40-
{
41-
var webPage = response.webPages.value[i];
39+
for (int i = 0; i < response.value.Length; i++)
40+
{
41+
var webPage = response.value[i];
4242

43-
Console.WriteLine("name: " + webPage.name);
44-
Console.WriteLine("url: " + webPage.url);
45-
Console.WriteLine("displayUrl: " + webPage.displayUrl);
46-
Console.WriteLine("snippet: " + webPage.snippet);
47-
Console.WriteLine("dateLastCrawled: " + webPage.dateLastCrawled);
43+
Console.WriteLine("Name: " + webPage.name);
44+
Console.WriteLine("WebSearchUrl: " + webPage.webSearchUrl);
45+
Console.WriteLine("HostPageUrl: " + webPage.hostPageUrl);
46+
Console.WriteLine("Thumbnail: " + webPage.thumbnail.width + " width, " + webPage.thumbnail.height + " height");
4847
Console.WriteLine();
49-
}
48+
}
5049
//</iterateResponse>
5150
}
5251
}
5352
// <responseClasses>
5453
public class BingCustomSearchResponse
55-
{
56-
public string _type{ get; set; }
57-
public WebPages webPages { get; set; }
58-
}
59-
60-
public class WebPages
6154
{
62-
public string webSearchUrl { get; set; }
63-
public int totalEstimatedMatches { get; set; }
64-
public WebPage[] value { get; set; }
55+
public string _type { get; set; }
56+
public WebPage[] value { get; set; }
6557
}
6658

6759
public class WebPage
6860
{
6961
public string name { get; set; }
70-
public string url { get; set; }
71-
public string displayUrl { get; set; }
72-
public string snippet { get; set; }
73-
public DateTime dateLastCrawled { get; set; }
74-
public string cachedPageUrl { get; set; }
75-
public OpenGraphImage openGraphImage { get; set; }
62+
public string webSearchUrl { get; set; }
63+
public string hostPageUrl { get; set; }
64+
public OpenGraphImage thumbnail { get; set; }
7665
}
7766

7867
public class OpenGraphImage
7968
{
80-
public string contentUrl { get; set; }
8169
public int width { get; set; }
8270
public int height { get; set; }
8371
}

0 commit comments

Comments
 (0)