Skip to content

Commit 4116c9e

Browse files
author
dksimpson
committed
Refresh Bing News Search REST API quickstarts
1 parent 00f5dfb commit 4116c9e

File tree

8 files changed

+101
-97
lines changed

8 files changed

+101
-97
lines changed

articles/cognitive-services/Bing-News-Search/csharp.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ manager: nitinme
88
ms.service: cognitive-services
99
ms.subservice: bing-news-search
1010
ms.topic: quickstart
11-
ms.date: 12/12/2019
11+
ms.date: 05/19/2020
1212
ms.author: aahi
1313
ms.custom: seodec2018
1414
---
1515

1616
# Quickstart: Search for news using C# and the Bing News Search REST API
1717

18-
Use this quickstart to make your first call to the Bing News Search API and view the JSON response. This simple C# application sends a news search query to the API, and displays the response. The full code to this sample can be found on [GitHub](https://github.com/Azure-Samples/cognitive-services-REST-api-samples/blob/master/dotnet/Search/BingNewsSearchv7.cs).
18+
Use this quickstart to make your first call to the Bing News Search API. This simple C# application sends a news search query to the API, and displays the JSON response. The full code to this sample can be found on [GitHub](https://github.com/Azure-Samples/cognitive-services-REST-api-samples/blob/master/dotnet/Search/BingNewsSearchv7.cs).
1919

20-
While this application is written in C#, the API is a RESTful Web service compatible with most programming languages.
20+
Although this application is written in C#, the API is a RESTful Web service compatible with most programming languages.
2121

2222
## Prerequisites
2323

2424
* Any edition of [Visual Studio 2017 or later](https://www.visualstudio.com/downloads/).
2525
* The [Json.NET](https://www.newtonsoft.com/json) framework, available as a NuGet package.
26-
* If you are using Linux/MacOS, this application can be run using [Mono](https://www.mono-project.com/).
26+
* If you're using Linux/MacOS, this application can be run using [Mono](https://www.mono-project.com/).
2727

2828
[!INCLUDE [cognitive-services-bing-news-search-signup-requirements](../../../includes/cognitive-services-bing-news-search-signup-requirements.md)]
2929

3030
## Create and initialize a project
3131

32-
1. create a new C# console solution in Visual Studio. Then add the following namespaces into the main code file.
32+
1. Create a new C# console solution in Visual Studio. Then, add the following namespaces into the main code file:
3333

3434
```csharp
3535
using System;
@@ -39,7 +39,7 @@ While this application is written in C#, the API is a RESTful Web service compat
3939
using System.Collections.Generic;
4040
```
4141

42-
2. Create variables for the API endpoint, your subscription key, and search term. You can use the global endpoint below, or the [custom subdomain](../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource.
42+
2. Create variables for the API endpoint, your subscription key, and search term. You can use the global endpoint in the following code, or use the [custom subdomain](../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource.
4343

4444
```csharp
4545
const string accessKey = "enter key here";
@@ -48,7 +48,7 @@ While this application is written in C#, the API is a RESTful Web service compat
4848
```
4949
## Create a struct to format the Bing News Search response
5050

51-
1. Define a `SearchResult` struct to contain the image search results, and JSON header information.
51+
1. Define a `SearchResult` struct to contain the image search results and JSON header information.
5252

5353
```csharp
5454
struct SearchResult
@@ -60,9 +60,9 @@ While this application is written in C#, the API is a RESTful Web service compat
6060

6161
## Create and handle a news search request
6262

63-
Create a method named `BingNewsSearch` to perform the call to the API, and set the return type to the `SearchResult` struct created earlier. In the method, perform the following steps:
63+
Create a method named `BingNewsSearch` to perform the call to the API, and set the return type to the `SearchResult` struct created previously. In the method, do the following steps:
6464

65-
1. Construct the URI for the search request. Note that the search term `toSearch` must be formatted before being appended to the string.
65+
1. Construct the URI for the search request. The `toSearch` search term must be formatted before it's appended to the string.
6666

6767
```csharp
6868
static SearchResult BingNewsSearch(string toSearch){
@@ -80,7 +80,7 @@ Create a method named `BingNewsSearch` to perform the call to the API, and set t
8080
string json = new StreamReader(response.GetResponseStream()).ReadToEnd();
8181
```
8282

83-
3. Create the search result object, and extract the Bing HTTP headers. Then return `searchResult`.
83+
3. Create the search result object, and extract the Bing HTTP headers. Then, return `searchResult`.
8484

8585
```csharp
8686
// Create the result object for return
@@ -101,7 +101,7 @@ Create a method named `BingNewsSearch` to perform the call to the API, and set t
101101

102102
## Process the response
103103

104-
1. In the main method, call `BingNewsSearch()` and store the returned response. Then deserialize the JSON into an object. You can then view the values of the response.
104+
In the main method, call `BingNewsSearch()` and store the returned response. Then deserialize the JSON into an object. You can then view the values of the response.
105105

106106
```csharp
107107
SearchResult result = BingNewsSearch(searchTerm);

articles/cognitive-services/Bing-News-Search/go.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ manager: nitinme
99
ms.service: cognitive-services
1010
ms.subservice: bing-visual-search
1111
ms.topic: quickstart
12-
ms.date: 12/16/2019
12+
ms.date: 05/19/2020
1313
ms.author: aahi
1414
---
1515

@@ -19,14 +19,13 @@ This quickstart uses the Go language to call the Bing News Search API. The resul
1919

2020
## Prerequisites
2121
* Install the [Go binaries](https://golang.org/dl/)
22-
* Install the go-spew library for it pretty printer to display results
23-
* Install this library: `$ go get -u https://github.com/davecgh/go-spew`
22+
* Install the go-spew library to use a deep pretty printer to display results. Use this command to install the library: `$ go get -u https://github.com/davecgh/go-spew`
2423

2524
[!INCLUDE [cognitive-services-bing-news-search-signup-requirements](../../../includes/cognitive-services-bing-news-search-signup-requirements.md)]
2625

2726
## Create a project and import libraries
2827

29-
Create a new Go project in your IDE or editor. Then import `net/http` for requests, `ioutil` to read the response, and `encoding/json` to handle the JSON text of results. The go-spew library is needed to parse JSON.
28+
Create a new Go project in your IDE or editor. Then, import `net/http` for requests, `ioutil` to read the response, and `encoding/json` to handle the JSON text of results. The go-spew library is needed to parse JSON.
3029

3130
```go
3231
package main
@@ -43,7 +42,7 @@ import (
4342

4443
## Create a struct to format the News search results
4544

46-
The `NewsAnswer` struct formats the data provided in the response. The response JSON is multilevel and quite complex. The following implementation covers the essentials.
45+
The `NewsAnswer` struct formats the data provided in the response JSON, which is multilevel and complex. The following implementation covers the essentials:
4746

4847
```go
4948
// This struct formats the answer provided by the Bing News Search API.
@@ -83,7 +82,7 @@ type NewsAnswer struct {
8382

8483
## Declare the main function and define variables
8584

86-
The following code declares the main function and assigns required variables. Confirm that the endpoint is correct and replace the `token` value with a valid subscription key from your Azure account. You can use the global endpoint below, or the [custom subdomain](../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource.
85+
The following code declares the main function and assigns required variables. Confirm that the endpoint is correct and replace the `token` value with a valid subscription key from your Azure account. You can use the global endpoint in the following code, or use the [custom subdomain](../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource.
8786

8887
```go
8988
func main() {
@@ -104,7 +103,7 @@ func main() {
104103

105104
## Query and header
106105

107-
Add the query string and access key header
106+
Add the query string and access key header.
108107

109108
```go
110109
// Add the query to the request.
@@ -135,7 +134,7 @@ if err != nil {
135134

136135
## Send the request
137136

138-
Send the request and read results using `ioutil`.
137+
Send the request and read results by using `ioutil`.
139138

140139
```go
141140
resp, err := client.Do(req)
@@ -156,7 +155,7 @@ if err != nil {
156155

157156
## Handle the response
158157

159-
The `Unmarshall` function extracts information from the JSON text returned by the News Search API. Then you can display nodes from the results using the `go-spew` pretty printer.
158+
The `Unmarshall` function extracts information from the JSON text returned by the News Search API. Then, you can display nodes from the results by using the `go-spew` pretty printer.
160159

161160
```go
162161
// Create a new answer object
@@ -177,7 +176,7 @@ spew.Dump(result.Name, result.URL)
177176

178177
## Results
179178

180-
The results contain name and URL of each result.
179+
The following output contains the name and URL of each result:
181180

182181
```
183182
(string) (len=91) "Cognitive Services Market: Global Industry Analysis and Opportunity Assessment, 2019 - 2025"

articles/cognitive-services/Bing-News-Search/java.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,30 @@ manager: nitinme
99
ms.service: cognitive-services
1010
ms.subservice: bing-news-search
1111
ms.topic: quickstart
12-
ms.date: 12/16/2019
12+
ms.date: 05/19/2020
1313
ms.author: aahi
1414
ms.custom: seodec2018
1515
---
1616

1717
# Quickstart: Perform a news search using Java and the Bing News Search REST API
1818

19-
Use this quickstart to make your first call to the Bing News Search API and view the JSON response. This simple Java application sends a news search query to the API, and displays the response.
19+
Use this quickstart to make your first call to the Bing News Search API. This simple Java application sends a news search query to the API, and displays the JSON response.
2020

21-
While this application is written in Java, the API is a RESTful Web service compatible with most programming languages.
21+
Although this application is written in Java, the API is a RESTful Web service compatible with most programming languages.
2222

23-
The source code for this sample is available [on GitHub](https://github.com/Azure-Samples/cognitive-services-REST-api-samples/blob/master/java/Search/BingNewsSearchv7.java)
23+
The source code for this sample is available [on GitHub](https://github.com/Azure-Samples/cognitive-services-REST-api-samples/blob/master/java/Search/BingNewsSearchv7.java).
2424

2525
## Prerequisites
2626

27-
* The [Java Development Kit(JDK) 7 or 8](https://aka.ms/azure-jdks)
28-
27+
* The [Java Development Kit (JDK) 7 or 8](https://aka.ms/azure-jdks)
2928
* The [Gson library](https://github.com/google/gson)
3029

3130

3231
[!INCLUDE [cognitive-services-bing-news-search-signup-requirements](../../../includes/cognitive-services-bing-news-search-signup-requirements.md)]
3332

3433
## Create and initialize a project
3534

36-
1. Create a new Java project in your favorite IDE or editor, and import the following libraries.
35+
1. Create a new Java project in your favorite IDE or editor, and import the following libraries:
3736

3837
```java
3938
import java.net.*;
@@ -46,7 +45,7 @@ The source code for this sample is available [on GitHub](https://github.com/Azur
4645
import com.google.gson.JsonParser;
4746
```
4847

49-
2. Create a new class, with variables for the API endpoint, your subscription key, and search term. You can use the global endpoint below, or the [custom subdomain](../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource.
48+
2. Create a new class, with variables for the API endpoint, your subscription key, and search term. You can use the global endpoint in the following code, or use the [custom subdomain](../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource.
5049

5150
```java
5251
public static SearchResults SearchNews (String searchQuery) throws Exception {
@@ -60,7 +59,7 @@ The source code for this sample is available [on GitHub](https://github.com/Azur
6059

6160
## Construct the search request, and receive a JSON response
6261

63-
1. Use the variables from the last step to format a search URL for the API request. Note that your search term must be URL-encoded before being appended to the request.
62+
1. Use the variables from the previous step to format a search URL for the API request. URL-encode your search term before you append it to the request.
6463

6564
```java
6665
public static SearchResults SearchNews (String searchQuery) throws Exception {
@@ -71,7 +70,7 @@ The source code for this sample is available [on GitHub](https://github.com/Azur
7170
}
7271
```
7372

74-
2. Receive the JSON response from the Bing News Search API, and construct the result object.
73+
2. Receive the JSON response from the Bing News Search API and construct the result object.
7574

7675
```java
7776
// receive JSON body
@@ -84,6 +83,7 @@ The source code for this sample is available [on GitHub](https://github.com/Azur
8483
## Process the JSON response
8584

8685
1. Separate the Bing-related HTTP headers from the JSON body, then close the stream and return the API response.
86+
8787
```java
8888
// extract Bing-related HTTP headers
8989
Map<String, List<String>> headers = connection.getHeaderFields();
@@ -97,7 +97,8 @@ The source code for this sample is available [on GitHub](https://github.com/Azur
9797
return results;
9898
```
9999

100-
2. Create a method to parse and reserialize JSON
100+
2. Create a method to parse and reserialize JSON.
101+
101102
```java
102103
// pretty-printer for JSON; uses GSON parser to parse and re-serialize
103104
public static String prettify(String json_text) {
@@ -108,7 +109,8 @@ The source code for this sample is available [on GitHub](https://github.com/Azur
108109
}
109110
```
110111

111-
3. In the main method of your application, call the search method, and display the results.
112+
3. In the main method of your application, call the search method and display the results.
113+
112114
```csharp
113115
public static void main (String[] args) {
114116
System.out.println("Searching the Web for: " + searchTerm);

articles/cognitive-services/Bing-News-Search/nodejs.md

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,35 @@ manager: nitinme
88
ms.service: cognitive-services
99
ms.subservice: bing-news-search
1010
ms.topic: quickstart
11-
ms.date: 12/12/2019
11+
ms.date: 05/19/2020
1212
ms.author: aahi
1313
ms.custom: seodec2018
1414
---
1515
# Quickstart: Perform a news search using Node.js and the Bing News Search REST API
1616

17-
Use this quickstart to make your first call to the Bing Image Search API and receive a JSON response. This simple JavaScript application sends a search query to the API and displays the raw results.
17+
Use this quickstart to make your first call to the Bing Image Search API. This simple JavaScript application sends a search query to the API and displays the JSON response.
1818

19-
While this application is written in JavaScript and runs in Node.js, the API is a RESTful Web service compatible most programming languages.
19+
Although this application is written in JavaScript and runs in Node.js, the API is a RESTful Web service compatible with most programming languages.
2020

2121
The source code for this sample is available on [GitHub](https://github.com/Azure-Samples/cognitive-services-REST-api-samples/blob/master/nodejs/Search/BingNewsSearchv7.js).
2222

2323
## Prerequisites
2424

2525
* The latest version of [Node.js](https://nodejs.org/en/download/).
26-
27-
* The [JavaScript Request Library](https://github.com/request/request)
26+
* The [JavaScript Request Library](https://github.com/request/request).
2827

2928
[!INCLUDE [cognitive-services-bing-news-search-signup-requirements](../../../includes/cognitive-services-bing-news-search-signup-requirements.md)]
3029

3130
## Create and initialize the application
3231

33-
1. Create a new JavaScript file in your favorite IDE or editor, and set the strictness and https requirements.
32+
1. Create a new JavaScript file in your favorite IDE or editor, and set the strictness and HTTPS requirements.
3433

3534
```javascript
3635
'use strict';
3736
let https = require('https');
3837
```
3938

40-
2. Create variables for the API endpoint, image API search path, your subscription key, and search term. You can use the global endpoint below, or the [custom subdomain](../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource.
39+
2. Create variables for the API endpoint, image API search path, your subscription key, and search term. You can use the global endpoint in the following code, or use the [custom subdomain](../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource.
4140

4241
```javascript
4342
let subscriptionKey = 'enter key here';
@@ -48,36 +47,38 @@ The source code for this sample is available on [GitHub](https://github.com/Azur
4847

4948
## Handle and parse the response
5049

51-
1. define a function named `response_handler` that takes an HTTP call, `response`, as a parameter. within this function, perform the following steps:
50+
1. Define a function, named `response_handler`, that takes an HTTP call, `response`, as a parameter.
5251

53-
1. Define a variable to contain the body of the JSON response.
54-
```javascript
55-
let response_handler = function (response) {
56-
let body = '';
57-
};
58-
```
52+
2. Within this function, define a variable to contain the body of the JSON response.
5953

60-
2. Store the body of the response when the **data** flag is called
61-
```javascript
62-
response.on('data', function (d) {
63-
body += d;
64-
});
54+
```javascript
55+
let response_handler = function (response) {
56+
let body = '';
57+
};
6558
```
6659

67-
3. When an **end** flag is signaled, the JSON and headers can be viewed.
68-
69-
```javascript
70-
response.on('end', function () {
71-
console.log('\nRelevant Headers:\n');
72-
for (var header in response.headers)
73-
// header keys are lower-cased by Node.js
74-
if (header.startsWith("bingapis-") || header.startsWith("x-msedge-"))
75-
console.log(header + ": " + response.headers[header]);
76-
body = JSON.stringify(JSON.parse(body), null, ' ');
77-
console.log('\nJSON Response:\n');
78-
console.log(body);
79-
});
80-
```
60+
3. Store the body of the response when the `data` flag is called.
61+
62+
```javascript
63+
response.on('data', function (d) {
64+
body += d;
65+
});
66+
```
67+
68+
3. When an `end` flag is signaled, the JSON and headers can be viewed.
69+
70+
```javascript
71+
response.on('end', function () {
72+
console.log('\nRelevant Headers:\n');
73+
for (var header in response.headers)
74+
// header keys are lower-cased by Node.js
75+
if (header.startsWith("bingapis-") || header.startsWith("x-msedge-"))
76+
console.log(header + ": " + response.headers[header]);
77+
body = JSON.stringify(JSON.parse(body), null, ' ');
78+
console.log('\nJSON Response:\n');
79+
console.log(body);
80+
});
81+
```
8182

8283
## JSON Response
8384

0 commit comments

Comments
 (0)