Skip to content

Commit a10ac62

Browse files
author
dksimpson
committed
Edits
1 parent b7b0e39 commit a10ac62

File tree

6 files changed

+54
-46
lines changed

6 files changed

+54
-46
lines changed

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

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ ms.custom: seodec2018
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. 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).
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.
1919

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

22+
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).
23+
2224
## Prerequisites
2325

2426
* Any edition of [Visual Studio 2017 or later](https://www.visualstudio.com/downloads/).
@@ -29,7 +31,7 @@ Although this application is written in C#, the API is a RESTful Web service com
2931

3032
## Create and initialize a project
3133

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

3436
```csharp
3537
using System;
@@ -61,44 +63,46 @@ struct SearchResult
6163

6264
## Create and handle a news search request
6365

64-
1. 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:
66+
1. Create a method named `BingNewsSearch()` to perform the call to the API, and set the return type to the `SearchResult` struct created previously.
6567

66-
1. Construct the URI for the search request. The `toSearch` search term must be formatted before it's appended to the string.
68+
Add code to this method in the steps that follow.
6769

68-
```csharp
69-
static SearchResult BingNewsSearch(string toSearch){
70+
1. Construct the URI for the search request. The `toSearch` search term must be formatted before it's appended to the string.
7071

71-
var uriQuery = uriBase + "?q=" + Uri.EscapeDataString(toSearch);
72-
//...
73-
```
72+
```csharp
73+
static SearchResult BingNewsSearch(string toSearch){
7474

75-
1. Perform the web request and get the response as a JSON string.
75+
var uriQuery = uriBase + "?q=" + Uri.EscapeDataString(toSearch);
76+
//...
77+
```
7678

77-
```csharp
78-
WebRequest request = WebRequest.Create(uriQuery);
79-
request.Headers["Ocp-Apim-Subscription-Key"] = subscriptionKey;
80-
HttpWebResponse response = (HttpWebResponse)request.GetResponseAsync().Result;
81-
string json = new StreamReader(response.GetResponseStream()).ReadToEnd();
82-
```
79+
1. Perform the web request and get the response as a JSON string.
8380

84-
1. Create the search result object, and extract the Bing HTTP headers. Then, return `searchResult`.
81+
```csharp
82+
WebRequest request = WebRequest.Create(uriQuery);
83+
request.Headers["Ocp-Apim-Subscription-Key"] = subscriptionKey;
84+
HttpWebResponse response = (HttpWebResponse)request.GetResponseAsync().Result;
85+
string json = new StreamReader(response.GetResponseStream()).ReadToEnd();
86+
```
8587

86-
```csharp
87-
// Create the result object for return
88-
var searchResult = new SearchResult()
89-
{
90-
jsonResult = json,
91-
relevantHeaders = new Dictionary<String, String>()
92-
};
88+
1. Create the search result object, and extract the Bing HTTP headers. Then, return `searchResult`.
9389

94-
// Extract Bing HTTP headers
95-
foreach (String header in response.Headers)
96-
{
97-
if (header.StartsWith("BingAPIs-") || header.StartsWith("X-MSEdge-"))
98-
searchResult.relevantHeaders[header] = response.Headers[header];
99-
}
100-
return searchResult;
101-
```
90+
```csharp
91+
// Create the result object for return
92+
var searchResult = new SearchResult()
93+
{
94+
jsonResult = json,
95+
relevantHeaders = new Dictionary<String, String>()
96+
};
97+
98+
// Extract Bing HTTP headers
99+
foreach (String header in response.Headers)
100+
{
101+
if (header.StartsWith("BingAPIs-") || header.StartsWith("X-MSEdge-"))
102+
searchResult.relevantHeaders[header] = response.Headers[header];
103+
}
104+
return searchResult;
105+
```
102106

103107
## Process the response
104108

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ ms.author: aahi
1818
This quickstart uses the Go language to call the Bing News Search API. The results include names and URLs of news sources identified by the query string.
1919

2020
## Prerequisites
21-
* Install the [Go binaries](https://golang.org/dl/)
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`
21+
* Install the [Go binaries](https://golang.org/dl/).
22+
* Install the go-spew library to use a deep pretty printer to display the results. Use this command to install the library: `$ go get -u https://github.com/davecgh/go-spew`.
2323

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

2626
## Create a project and import libraries
2727

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.
28+
Create a new Go project in your IDE or editor. Then, import `net/http` for requests, `ioutil` to read the response, `encoding/json` to handle the JSON text of results, and the go-spew library to parse the JSON results.
2929

3030
```go
3131
package main
@@ -40,7 +40,7 @@ import (
4040

4141
```
4242

43-
## Create a struct to format the News search results
43+
## Create a struct to format the news search results
4444

4545
The `NewsAnswer` struct formats the data provided in the response JSON, which is multilevel and complex. The following implementation covers the essentials:
4646

@@ -82,7 +82,7 @@ type NewsAnswer struct {
8282

8383
## Declare the main function and define variables
8484

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.
85+
The following code declares the main function and assigns the required variables. Confirm that the endpoint is correct, and then 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.
8686

8787
```go
8888
func main() {
@@ -134,7 +134,7 @@ if err != nil {
134134

135135
## Send the request
136136

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

139139
```go
140140
resp, err := client.Do(req)
@@ -155,7 +155,7 @@ if err != nil {
155155

156156
## Handle the response
157157

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.
158+
The `Unmarshall` function extracts information from the JSON text returned by the Bing News Search API. Then, display nodes from the results with the `go-spew` pretty printer.
159159

160160
```go
161161
// Create a new answer object

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ 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 the JSON results.
101101

102102
```java
103103
// pretty-printer for JSON; uses GSON parser to parse and re-serialize

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ The source code for this sample is available on [GitHub](https://github.com/Azur
4949

5050
1. Define a function named `response_handler` that takes an HTTP call, `response`, as a parameter.
5151

52-
2. Within this function, define a variable to contain the body of the JSON response.
52+
Add code to this function in the steps that follow.
53+
54+
2. Define a variable to contain the body of the JSON response.
5355

5456
```javascript
5557
let response_handler = function (response) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ For more information, see [Cognitive Services Pricing - Bing Search API](https:/
3131

3232
To run this application, follow these steps:
3333

34-
1. Make sure that secure HTTP support is enabled in your `php.ini` file, as described in the code comment.
34+
1. Enable secure HTTP support in your `php.ini` file by uncommenting the `;extension=php_openssl.dll` line, as described in the code comment.
3535
2. Create a new PHP project in your favorite IDE or editor.
3636
3. Add the code provided below.
3737
4. Replace the `accessKey` value with an access key valid for your subscription.
3838
5. 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.
39-
5. Run the program.
39+
6. Run the program.
4040

4141
```php
4242
<?php

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ ms.custom: seodec2018
1818

1919
Use this quickstart to make your first call to the Bing News Search API. This simple Ruby application sends a search query to the API and processes the JSON response.
2020

21-
Although this application is written in Ruby, the API is a RESTful Web service compatible with most programming languages. The source code for this sample is available on [GitHub](https://github.com/Azure-Samples/cognitive-services-REST-api-samples/blob/master/ruby/Search/BingNewsSearchv7.rb).
21+
Although this application is written in Ruby, the API is a RESTful Web service compatible with most programming languages.
22+
23+
The source code for this sample is available on [GitHub](https://github.com/Azure-Samples/cognitive-services-REST-api-samples/blob/master/ruby/Search/BingNewsSearchv7.rb).
2224

2325
## Prerequisites
2426

@@ -47,7 +49,7 @@ Although this application is written in Ruby, the API is a RESTful Web service c
4749

4850
## Format and make an API request
4951

50-
Use the variables from the last step to format a search URL for the API request. Then, send the request.
52+
Use the variables from the previous step to format a search URL for the API request. Then, send the request.
5153

5254
```ruby
5355
uri = URI(uri + path + "?q=" + URI.escape(term))
@@ -60,7 +62,7 @@ end
6062

6163
## Process and print the JSON response
6264

63-
After the response is received, you can parse the JSON, and print both the response body, and its headers.
65+
After the response is received, parse the JSON, and then print both the response body and its headers.
6466

6567
```ruby
6668
puts "\nRelevant Headers:\n\n"

0 commit comments

Comments
 (0)