Skip to content

Commit fcc9007

Browse files
authored
Merge pull request #114623 from dksimpson/DKS-US1712683-bing-image-search
[CogSvcs] Refresh Bing Image Search REST API quickstarts
2 parents 68b80c5 + b488109 commit fcc9007

File tree

7 files changed

+122
-118
lines changed

7 files changed

+122
-118
lines changed

articles/cognitive-services/Bing-Image-Search/quickstarts/csharp.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ manager: nitinme
88
ms.service: cognitive-services
99
ms.subservice: bing-image-search
1010
ms.topic: quickstart
11-
ms.date: 03/31/2020
11+
ms.date: 05/08/2020
1212
ms.author: aahi
1313
---
1414
# Quickstart: Search for images using the Bing Image Search REST API and C#
1515

16-
Use this quickstart to start sending search requests to the Bing Image Search API. This C# application sends a search query to the API, and displays the URL of the first image in the results. While this application is written in C#, the API is a RESTful web service compatible with most programming languages.
16+
Use this quickstart to learn how to send search requests to the Bing Image Search API. This C# application sends a search query to the API, and displays the URL of the first image in the results. Although this application is written in C#, the API is a RESTful web service compatible with most programming languages.
1717

1818
The source code for this sample is available [on GitHub](https://github.com/Azure-Samples/cognitive-services-REST-api-samples/blob/master/dotnet/Search/BingImageSearchv7Quickstart.cs) with additional error handling and annotations.
1919

@@ -26,7 +26,7 @@ The source code for this sample is available [on GitHub](https://github.com/Azur
2626

2727
## Create and initialize a project
2828

29-
1. create a new console solution named `BingSearchApisQuickStart` in Visual Studio. Then add the following namespaces into the main code file.
29+
1. Create a new console solution named `BingSearchApisQuickStart` in Visual Studio. Then, add the following namespaces to the main code file:
3030

3131
```csharp
3232
using System;
@@ -36,7 +36,7 @@ The source code for this sample is available [on GitHub](https://github.com/Azur
3636
using Newtonsoft.Json.Linq;
3737
```
3838

39-
2. Create variables for the API endpoint, your subscription key, and search term. `uriBase` can be 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, your subscription key, and search term. For `uriBase`, 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.
4040

4141
```csharp
4242
//...
@@ -53,7 +53,7 @@ The source code for this sample is available [on GitHub](https://github.com/Azur
5353

5454
## Create a struct to format the Bing Image Search response
5555

56-
Define a `SearchResult` struct to contain the image search results, and JSON header information.
56+
Define a `SearchResult` struct to contain the image search results and JSON header information.
5757

5858
```csharp
5959
namespace BingSearchApisQuickstart
@@ -71,7 +71,7 @@ Define a `SearchResult` struct to contain the image search results, and JSON hea
7171

7272
## Create a method to send search requests
7373

74-
Create a method named `BingImageSearch` to perform the call to the API, and set the return type to the `SearchResult` struct created earlier.
74+
Create a method named `BingImageSearch` to perform the call to the API, and set the return type to the `SearchResult` struct created previously.
7575

7676
```csharp
7777
//...
@@ -89,9 +89,9 @@ namespace BingSearchApisQuickstart
8989

9090
## Create and handle an image search request
9191

92-
In the `BingImageSearch` method, perform the following steps.
92+
In the `BingImageSearch` method, perform the following steps:
9393

94-
1. Construct the URI for the search request. The search term `SearchTerm` must be formatted before being appended to the string.
94+
1. Construct the URI for the search request. Format the `SearchTerm` search term before you append it to the string.
9595

9696
```csharp
9797
static SearchResult BingImageSearch(string SearchTerm){
@@ -109,7 +109,7 @@ In the `BingImageSearch` method, perform the following steps.
109109
string json = new StreamReader(response.GetResponseStream()).ReadToEnd();
110110
```
111111

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

114114
```csharp
115115
// Create the result object for return
@@ -130,7 +130,7 @@ In the `BingImageSearch` method, perform the following steps.
130130

131131
## Process and view the response
132132

133-
1. In the main method, call `BingImageSearch()` and store the returned response. Then deserialize the JSON into an object.
133+
1. In the main method, call `BingImageSearch()` and store the returned response. Then, deserialize the JSON into an object.
134134

135135
```csharp
136136
SearchResult result = BingImageSearch(searchTerm);
@@ -202,9 +202,9 @@ Responses from the Bing Image Search API are returned as JSON. This sample respo
202202
203203
## See also
204204

205-
* [What is Bing Image Search?](https://docs.microsoft.com/azure/cognitive-services/bing-image-search/overview)
206-
* [Try an online interactive demo](https://azure.microsoft.com/services/cognitive-services/bing-image-search-api/)
207-
* [Pricing details](https://azure.microsoft.com/pricing/details/cognitive-services/search-api/) for the Bing Search APIs.
208-
* [Get a free Cognitive Services access key](https://azure.microsoft.com/try/cognitive-services/?api=bing-image-search-api)
209-
* [Azure Cognitive Services Documentation](https://docs.microsoft.com/azure/cognitive-services)
210-
* [Bing Image Search API reference](https://docs.microsoft.com/rest/api/cognitiveservices-bingsearch/bing-images-api-v7-reference)
205+
* [What is the Bing Image Search API?](https://docs.microsoft.com/azure/cognitive-services/bing-image-search/overview)
206+
* [Try an online interactive demo](https://azure.microsoft.com/services/cognitive-services/bing-image-search-api/).
207+
* [Pricing details for the Bing Search APIs](https://azure.microsoft.com/pricing/details/cognitive-services/search-api/).
208+
* [Get a free Cognitive Services access key](https://azure.microsoft.com/try/cognitive-services/?api=bing-image-search-api).
209+
* [Azure Cognitive Services documentation](https://docs.microsoft.com/azure/cognitive-services).
210+
* [Bing Image Search API reference](https://docs.microsoft.com/rest/api/cognitiveservices-bingsearch/bing-images-api-v7-reference).

articles/cognitive-services/Bing-Image-Search/quickstarts/java.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ manager: nitinme
99
ms.service: cognitive-services
1010
ms.subservice: bing-image-search
1111
ms.topic: quickstart
12-
ms.date: 03/31/2020
12+
ms.date: 05/08/2020
1313
ms.author: aahi
1414
ms.custom: seodec2018, seo-java-july2019, seo-java-august2019, seo-java-september2019
1515
---
16-
# Quickstart: Search for images with the Bing Image Search API, an Azure cognitive service
16+
# Quickstart: Search for images with the Bing Image Search API and Java
1717

18-
Use this quickstart to send search requests to the Bing Image Search API in Azure Cognitive Services. This Java application sends a search query to the API, and displays the URL of the first image in the results. While this application is written in Java, the API is a RESTful web service compatible with most programming languages.
18+
Use this quickstart to learn how to send search requests to the Bing Image Search API in Azure Cognitive Services. This Java application sends a search query to the API, and displays the URL of the first image in the results. Although this application is written in Java, the API is a RESTful web service compatible with most programming languages.
1919

2020
The source code for this sample is available [on GitHub](https://github.com/Azure-Samples/cognitive-services-REST-api-samples/blob/master/java/Search/BingImageSearchv7Quickstart.java) with additional error handling and annotations.
2121

@@ -29,7 +29,7 @@ The source code for this sample is available [on GitHub](https://github.com/Azur
2929

3030
## Create and initialize a project
3131

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

3434
```java
3535
import java.net.*;
@@ -42,7 +42,7 @@ The source code for this sample is available [on GitHub](https://github.com/Azur
4242
import com.google.gson.JsonParser;
4343
```
4444

45-
2. Create variables for the API endpoint, your subscription key, and search term. `host` can be the global endpoint below, or the [custom subdomain](../../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource.
45+
2. Create variables for the API endpoint, your subscription key, and search term. For `host`, 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.
4646

4747
```java
4848
static String subscriptionKey = "enter key here";
@@ -53,7 +53,7 @@ The source code for this sample is available [on GitHub](https://github.com/Azur
5353

5454
## Construct the search request and query
5555

56-
1. Use the variables from the last step to format a search URL for the API request. The search term must be URL-encoded before being appended to the request.
56+
Use the variables from the previous step to format a search URL for the API request. URL-encode the search term before you appended it to the request.
5757

5858
```java
5959
// construct the search request URL (in the form of endpoint + query string)
@@ -64,7 +64,7 @@ The source code for this sample is available [on GitHub](https://github.com/Azur
6464

6565
## Receive and process the JSON response
6666

67-
1. Receive the JSON response from the Bing Image Search API, and construct the result object.
67+
1. Receive the JSON response from the Bing Image Search API and construct the result object.
6868

6969
```java
7070
// receive JSON body
@@ -73,7 +73,8 @@ The source code for this sample is available [on GitHub](https://github.com/Azur
7373
// construct result object for return
7474
SearchResults results = new SearchResults(new HashMap<String, String>(), response);
7575
```
76-
2. Separate the Bing-related HTTP headers from the JSON body
76+
2. Separate the Bing-related HTTP headers from the JSON body.
77+
7778
```java
7879
// extract Bing-related HTTP headers
7980
Map<String, List<String>> headers = connection.getHeaderFields();
@@ -85,7 +86,7 @@ The source code for this sample is available [on GitHub](https://github.com/Azur
8586
}
8687
```
8788

88-
3. Close the stream, and parse the response. Get the total number of returned search results, and the thumbnail url to the first image result.
89+
3. Close the stream, and parse the response. Get the total number of returned search results and the thumbnail url to the first image result.
8990

9091
```java
9192
stream.close();
@@ -154,9 +155,9 @@ Responses from the Bing Image Search API are returned as JSON. This sample respo
154155
155156
## See also
156157

157-
* [What is Bing Image Search?](https://docs.microsoft.com/azure/cognitive-services/bing-image-search/overview)
158-
* [Try an online interactive demo](https://azure.microsoft.com/services/cognitive-services/bing-image-search-api/)
159-
* [Pricing details](https://azure.microsoft.com/pricing/details/cognitive-services/search-api/) for the Bing Search APIs.
160-
* [Get a free Cognitive Services access key](https://azure.microsoft.com/try/cognitive-services/?api=bing-image-search-api)
161-
* [Azure Cognitive Services Documentation](https://docs.microsoft.com/azure/cognitive-services)
162-
* [Bing Image Search API reference](https://docs.microsoft.com/rest/api/cognitiveservices-bingsearch/bing-images-api-v7-reference)
158+
* [What is the Bing Image Search API?](https://docs.microsoft.com/azure/cognitive-services/bing-image-search/overview)
159+
* [Try an online interactive demo](https://azure.microsoft.com/services/cognitive-services/bing-image-search-api/).
160+
* [Pricing details for the Bing Search APIs](https://azure.microsoft.com/pricing/details/cognitive-services/search-api/).
161+
* [Get a free Cognitive Services access key](https://azure.microsoft.com/try/cognitive-services/?api=bing-image-search-api).
162+
* [Azure Cognitive Services documentation](https://docs.microsoft.com/azure/cognitive-services).
163+
* [Bing Image Search API reference](https://docs.microsoft.com/rest/api/cognitiveservices-bingsearch/bing-images-api-v7-reference).

articles/cognitive-services/Bing-Image-Search/quickstarts/nodejs.md

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
---
22
title: "Quickstart: Search for images using the Bing Image Search REST API and Node.js"
33
titleSuffix: Azure Cognitive Services
4-
description: Use this quickstart to send image search requests to the Bing Image Search REST API using JavaScript, and receive a JSON response.
4+
description: Use this quickstart to send image search requests to the Bing Image Search REST API using JavaScript, and JSON responses.
55
services: cognitive-services
66
documentationcenter: ''
77
author: aahill
88
manager: nitinme
99
ms.service: cognitive-services
1010
ms.subservice: bing-image-search
1111
ms.topic: quickstart
12-
ms.date: 03/31/2020
12+
ms.date: 05/08/2020
1313
ms.author: aahi
1414
ms.custom: seodec2018
1515
---
1616

1717
# Quickstart: Search for images using the Bing Image Search REST API and Node.js
1818

19-
Use this quickstart to start sending search requests to the Bing Image Search API. This JavaScript application sends a search query to the API, and displays the URL of the first image in the results. While this application is written in Javascript, the API is a RESTful web service compatible with most programming languages.
19+
Use this quickstart to learn how to send search requests to the Bing Image Search API. This JavaScript application sends a search query to the API, and displays the URL of the first image in the results. Although this application is written in JavaScript, 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/BingImageSearchv7Quickstart.js) with additional error handling and annotations.
2222

2323
## Prerequisites
2424

2525
* The latest version of [Node.js](https://nodejs.org/en/download/).
2626

27-
* The [JavaScript Request Library](https://github.com/request/request)
27+
* The [JavaScript Request Library](https://github.com/request/request).
2828

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

31-
See also [Cognitive Services Pricing - Bing Search API](https://azure.microsoft.com/pricing/details/cognitive-services/search-api/).
31+
For more information, see [Cognitive Services Pricing - Bing Search API](https://azure.microsoft.com/pricing/details/cognitive-services/search-api/).
3232

3333
## Create and initialize the application
3434

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

3737
```javascript
3838
'use strict';
3939
let https = require('https');
4040
```
4141

42-
2. Create variables for the API endpoint, image API search path, your subscription key, and search term. `host` can be 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, image API search path, your subscription key, and search term. For `host`, 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
```javascript
4545
let subscriptionKey = 'enter key here';
@@ -50,7 +50,7 @@ See also [Cognitive Services Pricing - Bing Search API](https://azure.microsoft.
5050

5151
## Construct the search request and query.
5252

53-
1. Use the variables from the last step to format a search URL for the API request. Your search term must be URL-encoded before being sent to the API.
53+
1. Use the variables from the last step to format a search URL for the API request. URL-encode your search term before you send it to the API.
5454

5555
```javascript
5656
let request_params = {
@@ -63,40 +63,42 @@ See also [Cognitive Services Pricing - Bing Search API](https://azure.microsoft.
6363
};
6464
```
6565

66-
2. Use the request library to send your query to the API. `response_handler` will be defined in the next section.
66+
2. Use the request library to send your query to the API.
6767
```javascript
6868
let req = https.request(request_params, response_handler);
6969
req.end();
7070
```
7171

7272
## Handle and parse the response
7373

74-
1. define a function named `response_handler` that takes an HTTP call, `response`, as a parameter. Do the following steps within this function:
75-
76-
1. Define a variable to contain the body of the JSON response.
77-
```javascript
78-
let response_handler = function (response) {
79-
let body = '';
80-
};
81-
```
82-
83-
2. Store the body of the response when the **data** flag is called
84-
```javascript
85-
response.on('data', function (d) {
86-
body += d;
87-
});
88-
```
89-
90-
3. When an **end** flag is signaled, get the first result from the JSON response. Print the URL for the first image, along with the total number of returned images.
91-
92-
```javascript
93-
response.on('end', function () {
94-
let firstImageResult = imageResults.value[0];
95-
console.log(`Image result count: ${imageResults.value.length}`);
96-
console.log(`First image thumbnail url: ${firstImageResult.thumbnailUrl}`);
97-
console.log(`First image web search url: ${firstImageResult.webSearchUrl}`);
98-
});
99-
```
74+
1. Define a function named `response_handler` that takes an HTTP call, `response`, as a parameter.
75+
76+
2. Within this function, define a variable to contain the body of the JSON response.
77+
78+
```javascript
79+
let response_handler = function (response) {
80+
let body = '';
81+
};
82+
```
83+
84+
3. Store the body of the response when the `data` flag is called.
85+
86+
```javascript
87+
response.on('data', function (d) {
88+
body += d;
89+
});
90+
```
91+
92+
4. When an `end` flag is signaled, get the first result from the JSON response. Print the URL for the first image, along with the total number of returned images.
93+
94+
```javascript
95+
response.on('end', function () {
96+
let firstImageResult = imageResults.value[0];
97+
console.log(`Image result count: ${imageResults.value.length}`);
98+
console.log(`First image thumbnail url: ${firstImageResult.thumbnailUrl}`);
99+
console.log(`First image web search url: ${firstImageResult.webSearchUrl}`);
100+
});
101+
```
100102

101103
## Example JSON response
102104

@@ -153,9 +155,9 @@ Responses from the Bing Image Search API are returned as JSON. This sample respo
153155

154156
## See also
155157

156-
* [What is Bing Image Search?](https://docs.microsoft.com/azure/cognitive-services/bing-image-search/overview)
157-
* [Try an online interactive demo](https://azure.microsoft.com/services/cognitive-services/bing-image-search-api/)
158-
* [Pricing details](https://azure.microsoft.com/pricing/details/cognitive-services/search-api/) for the Bing Search APIs.
159-
* [Get a free Cognitive Services access key](https://azure.microsoft.com/try/cognitive-services/?api=bing-image-search-api)
160-
* [Azure Cognitive Services Documentation](https://docs.microsoft.com/azure/cognitive-services)
161-
* [Bing Image Search API reference](https://docs.microsoft.com/rest/api/cognitiveservices-bingsearch/bing-images-api-v7-reference)
158+
* [What is the Bing Image Search API?](https://docs.microsoft.com/azure/cognitive-services/bing-image-search/overview)
159+
* [Try an online interactive demo](https://azure.microsoft.com/services/cognitive-services/bing-image-search-api/).
160+
* [Pricing details for the Bing Search APIs](https://azure.microsoft.com/pricing/details/cognitive-services/search-api/).
161+
* [Get a free Cognitive Services access key](https://azure.microsoft.com/try/cognitive-services/?api=bing-image-search-api).
162+
* [Azure Cognitive Services documentation](https://docs.microsoft.com/azure/cognitive-services).
163+
* [Bing Image Search API reference](https://docs.microsoft.com/rest/api/cognitiveservices-bingsearch/bing-images-api-v7-reference).

0 commit comments

Comments
 (0)