You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cognitive-services/Bing-Image-Search/quickstarts/csharp.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,12 +8,12 @@ manager: nitinme
8
8
ms.service: cognitive-services
9
9
ms.subservice: bing-image-search
10
10
ms.topic: quickstart
11
-
ms.date: 03/31/2020
11
+
ms.date: 05/08/2020
12
12
ms.author: aahi
13
13
---
14
14
# Quickstart: Search for images using the Bing Image Search REST API and C#
15
15
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.
17
17
18
18
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.
19
19
@@ -26,7 +26,7 @@ The source code for this sample is available [on GitHub](https://github.com/Azur
26
26
27
27
## Create and initialize a project
28
28
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:
30
30
31
31
```csharp
32
32
usingSystem;
@@ -36,7 +36,7 @@ The source code for this sample is available [on GitHub](https://github.com/Azur
36
36
usingNewtonsoft.Json.Linq;
37
37
```
38
38
39
-
2. Createvariablesfor 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) endpointdisplayedintheAzureportalfor your resource.
39
+
2. Createvariablesfor 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) endpointdisplayedintheAzureportalfor your resource.
40
40
41
41
```csharp
42
42
//...
@@ -53,7 +53,7 @@ The source code for this sample is available [on GitHub](https://github.com/Azur
53
53
54
54
## Create a struct to format the Bing Image Search response
55
55
56
-
Definea `SearchResult` structto contain the image search results, and JSON header information.
56
+
Definea `SearchResult` structto contain the image search results and JSON header information.
57
57
58
58
```csharp
59
59
namespace BingSearchApisQuickstart
@@ -71,7 +71,7 @@ Define a `SearchResult` struct to contain the image search results, and JSON hea
71
71
72
72
## Create a method to send search requests
73
73
74
-
Create a method named `BingImageSearch` to perform the call to theAPI, andsetthereturntypetothe `SearchResult` structcreatedearlier.
74
+
Create a method named `BingImageSearch` to perform the call to theAPI, andsetthereturntypetothe `SearchResult` structcreatedpreviously.
# 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
17
17
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.
19
19
20
20
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.
21
21
@@ -29,7 +29,7 @@ The source code for this sample is available [on GitHub](https://github.com/Azur
29
29
30
30
## Create and initialize a project
31
31
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:
33
33
34
34
```java
35
35
importjava.net.*;
@@ -42,7 +42,7 @@ The source code for this sample is available [on GitHub](https://github.com/Azur
42
42
importcom.google.gson.JsonParser;
43
43
```
44
44
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.
46
46
47
47
```java
48
48
staticString subscriptionKey ="enter key here";
@@ -53,7 +53,7 @@ The source code for this sample is available [on GitHub](https://github.com/Azur
53
53
54
54
## Construct the search request and query
55
55
56
-
1.Use the variables from the last step to format a search URLfor the API request. Thesearch term must be URL-encoded before being appended to the request.
56
+
Use the variables from the previous step to format a search URLfor the API request. URL-encode the search term before you appended it to the request.
57
57
58
58
```java
59
59
// 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
64
64
65
65
## Receive and process the JSON response
66
66
67
-
1.Receive the JSON response from the BingImageSearchAPI, and construct the result object.
67
+
1.Receive the JSON response from the BingImageSearchAPI and construct the result object.
68
68
69
69
```java
70
70
// receive JSON body
@@ -73,7 +73,8 @@ The source code for this sample is available [on GitHub](https://github.com/Azur
Copy file name to clipboardExpand all lines: articles/cognitive-services/Bing-Image-Search/quickstarts/nodejs.md
+43-41Lines changed: 43 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,45 +1,45 @@
1
1
---
2
2
title: "Quickstart: Search for images using the Bing Image Search REST API and Node.js"
3
3
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.
5
5
services: cognitive-services
6
6
documentationcenter: ''
7
7
author: aahill
8
8
manager: nitinme
9
9
ms.service: cognitive-services
10
10
ms.subservice: bing-image-search
11
11
ms.topic: quickstart
12
-
ms.date: 03/31/2020
12
+
ms.date: 05/08/2020
13
13
ms.author: aahi
14
14
ms.custom: seodec2018
15
15
---
16
16
17
17
# Quickstart: Search for images using the Bing Image Search REST API and Node.js
18
18
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.
20
20
21
21
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.
22
22
23
23
## Prerequisites
24
24
25
25
* The latest version of [Node.js](https://nodejs.org/en/download/).
26
26
27
-
* The [JavaScript Request Library](https://github.com/request/request)
27
+
* The [JavaScript Request Library](https://github.com/request/request).
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/).
32
32
33
33
## Create and initialize the application
34
34
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.
36
36
37
37
```javascript
38
38
'use strict';
39
39
let https =require('https');
40
40
```
41
41
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.
43
43
44
44
```javascript
45
45
let subscriptionKey = 'enter key here';
@@ -50,7 +50,7 @@ See also [Cognitive Services Pricing - Bing Search API](https://azure.microsoft.
50
50
51
51
## Construct the search request and query.
52
52
53
-
1. Use the variables from the last step to format a search URLfor the APIrequest. Yoursearch term must be URL-encoded before being sent to the API.
53
+
1. Use the variables from the last step to format a search URLfor the APIrequest. URL-encode your search term before you send it to the API.
54
54
55
55
```javascript
56
56
let request_params = {
@@ -63,40 +63,42 @@ See also [Cognitive Services Pricing - Bing Search API](https://azure.microsoft.
63
63
};
64
64
```
65
65
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.
67
67
```javascript
68
68
let req = https.request(request_params, response_handler);
69
69
req.end();
70
70
```
71
71
72
72
## Handle and parse the response
73
73
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 JSONresponse. Print the URLfor 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}`);
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 JSONresponse. Print the URLfor 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}`);
0 commit comments