Skip to content

Commit 249bbf7

Browse files
aahilllmazuel
authored andcommitted
adding new Bing Image Search quickstart sample (#16)
* adding new Bing Image Search quickstart sample * updating sample
1 parent 3d33117 commit 249bbf7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from azure.cognitiveservices.search.imagesearch import ImageSearchAPI
2+
from msrest.authentication import CognitiveServicesCredentials
3+
4+
subscription_key = "Enter your key here"
5+
search_term = "canadian rockies"
6+
7+
"""
8+
This application will search images on the web with the Bing Image Search API and print out first image result.
9+
"""
10+
#create the image search client
11+
client = ImageSearchAPI(CognitiveServicesCredentials(subscription_key))
12+
# send a search query to the Bing Image Search API
13+
image_results = client.images.search(query=search_term)
14+
print("Searching the web for images of: {}".format(search_term))
15+
16+
# Image results
17+
if image_results.value:
18+
first_image_result = image_results.value[0]
19+
print("Total number of images returned: {}".format(len(image_results.value)))
20+
print("First image thumbnail url: {}".format(first_image_result.thumbnail_url))
21+
print("First image content url: {}".format(first_image_result.content_url))
22+
else:
23+
print("Couldn't find image results!")

0 commit comments

Comments
 (0)