Skip to content

Commit 43f1203

Browse files
authored
Updated library
1 parent 7b4df0c commit 43f1203

File tree

1 file changed

+42
-26
lines changed

1 file changed

+42
-26
lines changed
Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,52 @@
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.
3+
34
// <vars>
45
var request = require("request");
5-
// Add your Bing Custom Search subscription key to your environment variables.
6-
// Your endpoint will have the form:
7-
// https://<your-custom-subdomain>.cognitiveservices.azure.com/bingcustomsearch/v7.0
6+
7+
/**
8+
* This sample uses the Bing Custom Search API to send a customized query
9+
* that returns a lot of data about the query with results.
10+
*/
11+
12+
// Add your Bing Custom Search subscription key and endpoint to your environment variables.
813
var subscriptionKey = process.env['BING_CUSTOM_SEARCH_SUBSCRIPTION_KEY'];
9-
var endpoint = process.env['BING_CUSTOM_SEARCH_ENDPOINT'];
10-
var customConfigId = 'YOUR-CUSTOM-CONFIG-ID'; //you can also use "1"
11-
var searchTerm = 'microsoft';
14+
var endpoint = process.env['BING_CUSTOM_SEARCH_ENDPOINT'] + "/bingcustomsearch/v7.0/search?";
15+
16+
var customConfigId = process.env['BING_CUSTOM_CONFIG']; //you can also use "1"
17+
18+
// Word(s) you want to search for.
19+
var query = 'Microsoft';
20+
// Market you want to search in.
21+
let mkt = 'en-US'
1222
// </vars>
23+
1324
// <requestOptions>
14-
var options = {
15-
url: endpoint + "/search?" +
16-
'q=' + searchTerm +
17-
'&customconfig=' + customConfigId,
25+
// Construct parameters
26+
let request_params = {
27+
uri: endpoint,
1828
headers: {
19-
'Ocp-Apim-Subscription-Key' : subscriptionKey
20-
}
29+
'Ocp-Apim-Subscription-Key': subscriptionKey
30+
},
31+
qs: {
32+
customConfig: customConfigId,
33+
q: query,
34+
mkt: mkt
35+
},
36+
json: true
2137
}
2238
// </requestOptions>
39+
2340
// <requestMethod>
24-
request(options, function(error, response, body){
25-
var searchResponse = JSON.parse(body);
26-
for(var i = 0; i < searchResponse.webPages.value.length; ++i){
27-
var webPage = searchResponse.webPages.value[i];
28-
console.log('name: ' + webPage.name);
29-
console.log('url: ' + webPage.url);
30-
console.log('displayUrl: ' + webPage.displayUrl);
31-
console.log('snippet: ' + webPage.snippet);
32-
console.log('dateLastCrawled: ' + webPage.dateLastCrawled);
33-
console.log();
34-
}
41+
// Make request
42+
request(request_params, function (error, response, body) {
43+
console.error('error:', error)
44+
console.log('statusCode:', response && response.statusCode)
45+
46+
console.log(body.queryContext)
47+
console.log()
48+
body.webPages.value.forEach(v => {
49+
console.log(v)
50+
})
3551
})
36-
// </requestMethod>
52+
// </requestMethod>

0 commit comments

Comments
 (0)