1package imagesearch 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "net/http" 25) 26 27// ImagesClient is the the Image Search API lets you send a search query to Bing and get back a list of relevant 28// images. This section provides technical details about the query parameters and headers that you use to request 29// images and the JSON response objects that contain them. For examples that show how to make requests, see [Searching 30// the Web for Images](https://docs.microsoft.com/azure/cognitive-services/bing-image-search/search-the-web). 31type ImagesClient struct { 32 BaseClient 33} 34 35// NewImagesClient creates an instance of the ImagesClient client. 36func NewImagesClient() ImagesClient { 37 return NewImagesClientWithBaseURI(DefaultBaseURI) 38} 39 40// NewImagesClientWithBaseURI creates an instance of the ImagesClient client. 41func NewImagesClientWithBaseURI(baseURI string) ImagesClient { 42 return ImagesClient{NewWithBaseURI(baseURI)} 43} 44 45// Details sends the details request. 46// Parameters: 47// query - the user's search query term. The term cannot be empty. The term may contain [Bing Advanced 48// Operators](http://msdn.microsoft.com/library/ff795620.aspx). For example, to limit images to a specific 49// domain, use the [site:](http://msdn.microsoft.com/library/ff795613.aspx) operator. To help improve relevance 50// of an insights query (see 51// [insightsToken](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#insightstoken)), 52// you should always include the user's query term. Use this parameter only with the Image Search API.Do not 53// specify this parameter when calling the Trending Images API. 54// acceptLanguage - a comma-delimited list of one or more languages to use for user interface strings. The list 55// is in decreasing order of preference. For additional information, including expected format, see 56// [RFC2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). This header and the 57// [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#setlang) 58// query parameter are mutually exclusive; do not specify both. If you set this header, you must also specify 59// the [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#cc) query 60// parameter. To determine the market to return results for, Bing uses the first supported language it finds 61// from the list and combines it with the cc parameter value. If the list does not include a supported 62// language, Bing finds the closest language and market that supports the request or it uses an aggregated or 63// default market for the results. To determine the market that Bing used, see the BingAPIs-Market header. Use 64// this header and the cc query parameter only if you specify multiple languages. Otherwise, use the 65// [mkt](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#mkt) and 66// [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#setlang) 67// query parameters. A user interface string is a string that's used as a label in a user interface. There are 68// few user interface strings in the JSON response objects. Any links to Bing.com properties in the response 69// objects apply the specified language. 70// contentType - optional request header. If you set the 71// [modules](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#modulesrequested) 72// query parameter to RecognizedEntities, you may specify the binary of an image in the body of a POST request. 73// If you specify the image in the body of a POST request, you must specify this header and set its value to 74// multipart/form-data. The maximum image size is 1 MB. 75// userAgent - the user agent originating the request. Bing uses the user agent to provide mobile users with an 76// optimized experience. Although optional, you are encouraged to always specify this header. The user-agent 77// should be the same string that any commonly used browser sends. For information about user agents, see [RFC 78// 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). The following are examples of user-agent 79// strings. Windows Phone: Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; 80// ARM; Touch; NOKIA; Lumia 822). Android: Mozilla / 5.0 (Linux; U; Android 2.3.5; en - us; SCH - I500 Build / 81// GINGERBREAD) AppleWebKit / 533.1 (KHTML; like Gecko) Version / 4.0 Mobile Safari / 533.1. iPhone: Mozilla / 82// 5.0 (iPhone; CPU iPhone OS 6_1 like Mac OS X) AppleWebKit / 536.26 (KHTML; like Gecko) Mobile / 10B142 83// iPhone4; 1 BingWeb / 3.03.1428.20120423. PC: Mozilla / 5.0 (Windows NT 6.3; WOW64; Trident / 7.0; Touch; 84// rv:11.0) like Gecko. iPad: Mozilla / 5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit / 537.51.1 (KHTML, 85// like Gecko) Version / 7.0 Mobile / 11A465 Safari / 9537.53 86// clientID - bing uses this header to provide users with consistent behavior across Bing API calls. Bing often 87// flights new features and improvements, and it uses the client ID as a key for assigning traffic on different 88// flights. If you do not use the same client ID for a user across multiple requests, then Bing may assign the 89// user to multiple conflicting flights. Being assigned to multiple conflicting flights can lead to an 90// inconsistent user experience. For example, if the second request has a different flight assignment than the 91// first, the experience may be unexpected. Also, Bing can use the client ID to tailor web results to that 92// client ID’s search history, providing a richer experience for the user. Bing also uses this header to help 93// improve result rankings by analyzing the activity generated by a client ID. The relevance improvements help 94// with better quality of results delivered by Bing APIs and in turn enables higher click-through rates for the 95// API consumer. IMPORTANT: Although optional, you should consider this header required. Persisting the client 96// ID across multiple requests for the same end user and device combination enables 1) the API consumer to 97// receive a consistent user experience, and 2) higher click-through rates via better quality of results from 98// the Bing APIs. Each user that uses your application on the device must have a unique, Bing generated client 99// ID. If you do not include this header in the request, Bing generates an ID and returns it in the 100// X-MSEdge-ClientID response header. The only time that you should NOT include this header in a request is the 101// first time the user uses your app on that device. Use the client ID for each Bing API request that your app 102// makes for this user on the device. Persist the client ID. To persist the ID in a browser app, use a 103// persistent HTTP cookie to ensure the ID is used across all sessions. Do not use a session cookie. For other 104// apps such as mobile apps, use the device's persistent storage to persist the ID. The next time the user uses 105// your app on that device, get the client ID that you persisted. Bing responses may or may not include this 106// header. If the response includes this header, capture the client ID and use it for all subsequent Bing 107// requests for the user on that device. If you include the X-MSEdge-ClientID, you must not include cookies in 108// the request. 109// clientIP - the IPv4 or IPv6 address of the client device. The IP address is used to discover the user's 110// location. Bing uses the location information to determine safe search behavior. Although optional, you are 111// encouraged to always specify this header and the X-Search-Location header. Do not obfuscate the address (for 112// example, by changing the last octet to 0). Obfuscating the address results in the location not being 113// anywhere near the device's actual location, which may result in Bing serving erroneous results. 114// location - a semicolon-delimited list of key/value pairs that describe the client's geographical location. 115// Bing uses the location information to determine safe search behavior and to return relevant local content. 116// Specify the key/value pair as <key>:<value>. The following are the keys that you use to specify the user's 117// location. lat (required): The latitude of the client's location, in degrees. The latitude must be greater 118// than or equal to -90.0 and less than or equal to +90.0. Negative values indicate southern latitudes and 119// positive values indicate northern latitudes. long (required): The longitude of the client's location, in 120// degrees. The longitude must be greater than or equal to -180.0 and less than or equal to +180.0. Negative 121// values indicate western longitudes and positive values indicate eastern longitudes. re (required): The 122// radius, in meters, which specifies the horizontal accuracy of the coordinates. Pass the value returned by 123// the device's location service. Typical values might be 22m for GPS/Wi-Fi, 380m for cell tower triangulation, 124// and 18,000m for reverse IP lookup. ts (optional): The UTC UNIX timestamp of when the client was at the 125// location. (The UNIX timestamp is the number of seconds since January 1, 1970.) head (optional): The client's 126// relative heading or direction of travel. Specify the direction of travel as degrees from 0 through 360, 127// counting clockwise relative to true north. Specify this key only if the sp key is nonzero. sp (optional): 128// The horizontal velocity (speed), in meters per second, that the client device is traveling. alt (optional): 129// The altitude of the client device, in meters. are (optional): The radius, in meters, that specifies the 130// vertical accuracy of the coordinates. Specify this key only if you specify the alt key. Although many of the 131// keys are optional, the more information that you provide, the more accurate the location results are. 132// Although optional, you are encouraged to always specify the user's geographical location. Providing the 133// location is especially important if the client's IP address does not accurately reflect the user's physical 134// location (for example, if the client uses VPN). For optimal results, you should include this header and the 135// X-MSEdge-ClientIP header, but at a minimum, you should include this header. 136// cropBottom - the bottom coordinate of the region to crop. The coordinate is a fractional value of the 137// original image's height and is measured from the top, left corner of the image. Specify the coordinate as a 138// value from 0.0 through 1.0. Use this parameter only with the Insights API. Do not specify this parameter 139// when calling the Images, Trending Images, or Web Search APIs. 140// cropLeft - the left coordinate of the region to crop. The coordinate is a fractional value of the original 141// image's height and is measured from the top, left corner of the image. Specify the coordinate as a value 142// from 0.0 through 1.0. Use this parameter only with the Insights API. Do not specify this parameter when 143// calling the Images, Trending Images, or Web Search APIs. 144// cropRight - the right coordinate of the region to crop. The coordinate is a fractional value of the original 145// image's height and is measured from the top, left corner of the image. Specify the coordinate as a value 146// from 0.0 through 1.0. Use this parameter only with the Insights API. Do not specify this parameter when 147// calling the Images, Trending Images, or Web Search APIs. 148// cropTop - the top coordinate of the region to crop. The coordinate is a fractional value of the original 149// image's height and is measured from the top, left corner of the image. Specify the coordinate as a value 150// from 0.0 through 1.0. Use this parameter only with the Insights API. Do not specify this parameter when 151// calling the Images, Trending Images, or Web Search APIs. 152// cropType - the crop type to use when cropping the image based on the coordinates specified in the cal, cat, 153// car, and cab parameters. The following are the possible values. 0: Rectangular (default). Use this parameter 154// only with the Insights API. Do not specify this parameter when calling the Images, Trending Images, or Web 155// Search APIs. 156// countryCode - a 2-character country code of the country where the results come from. For a list of possible 157// values, see [Market 158// Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes). 159// If you set this parameter, you must also specify the 160// [Accept-Language](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#acceptlanguage) 161// header. Bing uses the first supported language it finds from the languages list, and combine that language 162// with the country code that you specify to determine the market to return results for. If the languages list 163// does not include a supported language, Bing finds the closest language and market that supports the request, 164// or it may use an aggregated or default market for the results instead of a specified one. You should use 165// this query parameter and the Accept-Language query parameter only if you specify multiple languages; 166// otherwise, you should use the mkt and setLang query parameters. This parameter and the 167// [mkt](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#mkt) query 168// parameter are mutually exclusive—do not specify both. 169// ID - an ID that uniquely identifies an image. Use this parameter to ensure that the specified image is the 170// first image in the list of images that Bing returns. The 171// [Image](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#image) 172// object's imageId field contains the ID that you set this parameter to. 173// imageURL - the URL of an image that you want to get insights of. Use this parameter as an alternative to 174// using the insightsToken parameter to specify the image. You may also specify the image by placing the binary 175// of the image in the body of a POST request. If you use the binary option, see the 176// [Content-Type](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#contenttype) 177// header. The maximum supported image size is 1 MB. Use this parameter only with the Insights API. Do not 178// specify this parameter when calling the Images, Trending Images, or Web Search APIs. 179// insightsToken - an image token. The 180// [Image](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#image) 181// object's 182// [imageInsightsToken](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#image-imageinsightstoken) 183// contains the token. Specify this parameter to get additional information about an image, such as a caption 184// or shopping source. For a list of the additional information about an image that you can get, see the 185// [modules](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#modulesrequested) 186// query parameter. Use this parameter only with the Insights API. Do not specify this parameter when calling 187// the Images, Trending Images, or Web Search APIs. 188// modules - a comma-delimited list of insights to request. The following are the possible case-insensitive 189// values. All: Return all insights, if available, except RecognizedEntities. BRQ: Best representative query. 190// The query term that best describes the image. Caption: A caption that provides information about the image. 191// If the caption contains entities, the response may include links to images of those entities. Collections: A 192// list of related images. Recipes: A list of recipes for cooking the food shown in the images. PagesIncluding: 193// A list of webpages that include the image. RecognizedEntities: A list of entities (people) that were 194// recognized in the image. NOTE: You may not specify this module with any other module. If you specify it with 195// other modules, the response doesn't include recognized entities. RelatedSearches: A list of related searches 196// made by others. ShoppingSources: A list of merchants where you can buy related offerings. SimilarImages: A 197// list of images that are visually similar to the original image. SimilarProducts: A list of images that 198// contain a product that is similar to a product found in the original image. Tags: Provides characteristics 199// of the type of content found in the image. For example, if the image is of a person, the tags might indicate 200// the person's gender and type of clothes they're wearing. If you specify a module and there is no data for 201// the module, the response object doesn't include the related field. For example, if you specify Caption and 202// it does not exist, the response doesn't include the imageCaption field. To include related searches, the 203// request must include the original query string. Although the original query string is not required for 204// similar images or products, you should always include it because it can help improve relevance and the 205// results. Use this parameter only with the Insights API. Do not specify this parameter when calling the 206// Images, Trending Images, or Web Search APIs. 207// market - the market where the results come from. Typically, mkt is the country where the user is making the 208// request from. However, it could be a different country if the user is not located in a country where Bing 209// delivers results. The market must be in the form <language code>-<country code>. For example, en-US. The 210// string is case insensitive. For a list of possible market values, see [Market 211// Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes). 212// NOTE: If known, you are encouraged to always specify the market. Specifying the market helps Bing route the 213// request and return an appropriate and optimal response. If you specify a market that is not listed in 214// [Market 215// Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes), 216// Bing uses a best fit market code based on an internal mapping that is subject to change. This parameter and 217// the [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#cc) query 218// parameter are mutually exclusive—do not specify both. 219// safeSearch - filter images for adult content. The following are the possible filter values. Off: May return 220// images with adult content. If the request is through the Image Search API, the response includes thumbnail 221// images that are clear (non-fuzzy). However, if the request is through the Web Search API, the response 222// includes thumbnail images that are pixelated (fuzzy). Moderate: If the request is through the Image Search 223// API, the response doesn't include images with adult content. If the request is through the Web Search API, 224// the response may include images with adult content (the thumbnail images are pixelated (fuzzy)). Strict: Do 225// not return images with adult content. The default is Moderate. If the request comes from a market that 226// Bing's adult policy requires that safeSearch is set to Strict, Bing ignores the safeSearch value and uses 227// Strict. If you use the site: query operator, there is the chance that the response may contain adult content 228// regardless of what the safeSearch query parameter is set to. Use site: only if you are aware of the content 229// on the site and your scenario supports the possibility of adult content. 230// setLang - the language to use for user interface strings. Specify the language using the ISO 639-1 2-letter 231// language code. For example, the language code for English is EN. The default is EN (English). Although 232// optional, you should always specify the language. Typically, you set setLang to the same language specified 233// by mkt unless the user wants the user interface strings displayed in a different language. This parameter 234// and the 235// [Accept-Language](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#acceptlanguage) 236// header are mutually exclusive; do not specify both. A user interface string is a string that's used as a 237// label in a user interface. There are few user interface strings in the JSON response objects. Also, any 238// links to Bing.com properties in the response objects apply the specified language. 239func (client ImagesClient) Details(ctx context.Context, query string, acceptLanguage string, contentType string, userAgent string, clientID string, clientIP string, location string, cropBottom *float64, cropLeft *float64, cropRight *float64, cropTop *float64, cropType ImageCropType, countryCode string, ID string, imageURL string, insightsToken string, modules []ImageInsightModule, market string, safeSearch SafeSearch, setLang string) (result ImageInsights, err error) { 240 req, err := client.DetailsPreparer(ctx, query, acceptLanguage, contentType, userAgent, clientID, clientIP, location, cropBottom, cropLeft, cropRight, cropTop, cropType, countryCode, ID, imageURL, insightsToken, modules, market, safeSearch, setLang) 241 if err != nil { 242 err = autorest.NewErrorWithError(err, "imagesearch.ImagesClient", "Details", nil, "Failure preparing request") 243 return 244 } 245 246 resp, err := client.DetailsSender(req) 247 if err != nil { 248 result.Response = autorest.Response{Response: resp} 249 err = autorest.NewErrorWithError(err, "imagesearch.ImagesClient", "Details", resp, "Failure sending request") 250 return 251 } 252 253 result, err = client.DetailsResponder(resp) 254 if err != nil { 255 err = autorest.NewErrorWithError(err, "imagesearch.ImagesClient", "Details", resp, "Failure responding to request") 256 } 257 258 return 259} 260 261// DetailsPreparer prepares the Details request. 262func (client ImagesClient) DetailsPreparer(ctx context.Context, query string, acceptLanguage string, contentType string, userAgent string, clientID string, clientIP string, location string, cropBottom *float64, cropLeft *float64, cropRight *float64, cropTop *float64, cropType ImageCropType, countryCode string, ID string, imageURL string, insightsToken string, modules []ImageInsightModule, market string, safeSearch SafeSearch, setLang string) (*http.Request, error) { 263 queryParameters := map[string]interface{}{ 264 "q": autorest.Encode("query", query), 265 } 266 if cropBottom != nil { 267 queryParameters["cab"] = autorest.Encode("query", *cropBottom) 268 } 269 if cropLeft != nil { 270 queryParameters["cal"] = autorest.Encode("query", *cropLeft) 271 } 272 if cropRight != nil { 273 queryParameters["car"] = autorest.Encode("query", *cropRight) 274 } 275 if cropTop != nil { 276 queryParameters["cat"] = autorest.Encode("query", *cropTop) 277 } 278 if len(string(cropType)) > 0 { 279 queryParameters["ct"] = autorest.Encode("query", cropType) 280 } 281 if len(countryCode) > 0 { 282 queryParameters["cc"] = autorest.Encode("query", countryCode) 283 } 284 if len(ID) > 0 { 285 queryParameters["id"] = autorest.Encode("query", ID) 286 } 287 if len(imageURL) > 0 { 288 queryParameters["imgUrl"] = autorest.Encode("query", imageURL) 289 } 290 if len(insightsToken) > 0 { 291 queryParameters["insightsToken"] = autorest.Encode("query", insightsToken) 292 } 293 if modules != nil && len(modules) > 0 { 294 queryParameters["modules"] = autorest.Encode("query", modules, ",") 295 } 296 if len(market) > 0 { 297 queryParameters["mkt"] = autorest.Encode("query", market) 298 } 299 if len(string(safeSearch)) > 0 { 300 queryParameters["safeSearch"] = autorest.Encode("query", safeSearch) 301 } 302 if len(setLang) > 0 { 303 queryParameters["setLang"] = autorest.Encode("query", setLang) 304 } 305 306 preparer := autorest.CreatePreparer( 307 autorest.AsGet(), 308 autorest.WithBaseURL(client.BaseURI), 309 autorest.WithPath("/images/details"), 310 autorest.WithQueryParameters(queryParameters), 311 autorest.WithHeader("X-BingApis-SDK", "true")) 312 if len(acceptLanguage) > 0 { 313 preparer = autorest.DecoratePreparer(preparer, 314 autorest.WithHeader("Accept-Language", autorest.String(acceptLanguage))) 315 } 316 if len(contentType) > 0 { 317 preparer = autorest.DecoratePreparer(preparer, 318 autorest.WithHeader("Content-Type", autorest.String(contentType))) 319 } 320 if len(userAgent) > 0 { 321 preparer = autorest.DecoratePreparer(preparer, 322 autorest.WithHeader("User-Agent", autorest.String(userAgent))) 323 } 324 if len(clientID) > 0 { 325 preparer = autorest.DecoratePreparer(preparer, 326 autorest.WithHeader("X-MSEdge-ClientID", autorest.String(clientID))) 327 } 328 if len(clientIP) > 0 { 329 preparer = autorest.DecoratePreparer(preparer, 330 autorest.WithHeader("X-MSEdge-ClientIP", autorest.String(clientIP))) 331 } 332 if len(location) > 0 { 333 preparer = autorest.DecoratePreparer(preparer, 334 autorest.WithHeader("X-Search-Location", autorest.String(location))) 335 } 336 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 337} 338 339// DetailsSender sends the Details request. The method will close the 340// http.Response Body if it receives an error. 341func (client ImagesClient) DetailsSender(req *http.Request) (*http.Response, error) { 342 return autorest.SendWithSender(client, req, 343 autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 344} 345 346// DetailsResponder handles the response to the Details request. The method always 347// closes the http.Response Body. 348func (client ImagesClient) DetailsResponder(resp *http.Response) (result ImageInsights, err error) { 349 err = autorest.Respond( 350 resp, 351 client.ByInspecting(), 352 azure.WithErrorUnlessStatusCode(http.StatusOK), 353 autorest.ByUnmarshallingJSON(&result), 354 autorest.ByClosing()) 355 result.Response = autorest.Response{Response: resp} 356 return 357} 358 359// Search sends the search request. 360// Parameters: 361// query - the user's search query term. The term cannot be empty. The term may contain [Bing Advanced 362// Operators](http://msdn.microsoft.com/library/ff795620.aspx). For example, to limit images to a specific 363// domain, use the [site:](http://msdn.microsoft.com/library/ff795613.aspx) operator. To help improve relevance 364// of an insights query (see 365// [insightsToken](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#insightstoken)), 366// you should always include the user's query term. Use this parameter only with the Image Search API.Do not 367// specify this parameter when calling the Trending Images API. 368// acceptLanguage - a comma-delimited list of one or more languages to use for user interface strings. The list 369// is in decreasing order of preference. For additional information, including expected format, see 370// [RFC2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). This header and the 371// [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#setlang) 372// query parameter are mutually exclusive; do not specify both. If you set this header, you must also specify 373// the [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#cc) query 374// parameter. To determine the market to return results for, Bing uses the first supported language it finds 375// from the list and combines it with the cc parameter value. If the list does not include a supported 376// language, Bing finds the closest language and market that supports the request or it uses an aggregated or 377// default market for the results. To determine the market that Bing used, see the BingAPIs-Market header. Use 378// this header and the cc query parameter only if you specify multiple languages. Otherwise, use the 379// [mkt](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#mkt) and 380// [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#setlang) 381// query parameters. A user interface string is a string that's used as a label in a user interface. There are 382// few user interface strings in the JSON response objects. Any links to Bing.com properties in the response 383// objects apply the specified language. 384// userAgent - the user agent originating the request. Bing uses the user agent to provide mobile users with an 385// optimized experience. Although optional, you are encouraged to always specify this header. The user-agent 386// should be the same string that any commonly used browser sends. For information about user agents, see [RFC 387// 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). The following are examples of user-agent 388// strings. Windows Phone: Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; 389// ARM; Touch; NOKIA; Lumia 822). Android: Mozilla / 5.0 (Linux; U; Android 2.3.5; en - us; SCH - I500 Build / 390// GINGERBREAD) AppleWebKit / 533.1 (KHTML; like Gecko) Version / 4.0 Mobile Safari / 533.1. iPhone: Mozilla / 391// 5.0 (iPhone; CPU iPhone OS 6_1 like Mac OS X) AppleWebKit / 536.26 (KHTML; like Gecko) Mobile / 10B142 392// iPhone4; 1 BingWeb / 3.03.1428.20120423. PC: Mozilla / 5.0 (Windows NT 6.3; WOW64; Trident / 7.0; Touch; 393// rv:11.0) like Gecko. iPad: Mozilla / 5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit / 537.51.1 (KHTML, 394// like Gecko) Version / 7.0 Mobile / 11A465 Safari / 9537.53 395// clientID - bing uses this header to provide users with consistent behavior across Bing API calls. Bing often 396// flights new features and improvements, and it uses the client ID as a key for assigning traffic on different 397// flights. If you do not use the same client ID for a user across multiple requests, then Bing may assign the 398// user to multiple conflicting flights. Being assigned to multiple conflicting flights can lead to an 399// inconsistent user experience. For example, if the second request has a different flight assignment than the 400// first, the experience may be unexpected. Also, Bing can use the client ID to tailor web results to that 401// client ID’s search history, providing a richer experience for the user. Bing also uses this header to help 402// improve result rankings by analyzing the activity generated by a client ID. The relevance improvements help 403// with better quality of results delivered by Bing APIs and in turn enables higher click-through rates for the 404// API consumer. IMPORTANT: Although optional, you should consider this header required. Persisting the client 405// ID across multiple requests for the same end user and device combination enables 1) the API consumer to 406// receive a consistent user experience, and 2) higher click-through rates via better quality of results from 407// the Bing APIs. Each user that uses your application on the device must have a unique, Bing generated client 408// ID. If you do not include this header in the request, Bing generates an ID and returns it in the 409// X-MSEdge-ClientID response header. The only time that you should NOT include this header in a request is the 410// first time the user uses your app on that device. Use the client ID for each Bing API request that your app 411// makes for this user on the device. Persist the client ID. To persist the ID in a browser app, use a 412// persistent HTTP cookie to ensure the ID is used across all sessions. Do not use a session cookie. For other 413// apps such as mobile apps, use the device's persistent storage to persist the ID. The next time the user uses 414// your app on that device, get the client ID that you persisted. Bing responses may or may not include this 415// header. If the response includes this header, capture the client ID and use it for all subsequent Bing 416// requests for the user on that device. If you include the X-MSEdge-ClientID, you must not include cookies in 417// the request. 418// clientIP - the IPv4 or IPv6 address of the client device. The IP address is used to discover the user's 419// location. Bing uses the location information to determine safe search behavior. Although optional, you are 420// encouraged to always specify this header and the X-Search-Location header. Do not obfuscate the address (for 421// example, by changing the last octet to 0). Obfuscating the address results in the location not being 422// anywhere near the device's actual location, which may result in Bing serving erroneous results. 423// location - a semicolon-delimited list of key/value pairs that describe the client's geographical location. 424// Bing uses the location information to determine safe search behavior and to return relevant local content. 425// Specify the key/value pair as <key>:<value>. The following are the keys that you use to specify the user's 426// location. lat (required): The latitude of the client's location, in degrees. The latitude must be greater 427// than or equal to -90.0 and less than or equal to +90.0. Negative values indicate southern latitudes and 428// positive values indicate northern latitudes. long (required): The longitude of the client's location, in 429// degrees. The longitude must be greater than or equal to -180.0 and less than or equal to +180.0. Negative 430// values indicate western longitudes and positive values indicate eastern longitudes. re (required): The 431// radius, in meters, which specifies the horizontal accuracy of the coordinates. Pass the value returned by 432// the device's location service. Typical values might be 22m for GPS/Wi-Fi, 380m for cell tower triangulation, 433// and 18,000m for reverse IP lookup. ts (optional): The UTC UNIX timestamp of when the client was at the 434// location. (The UNIX timestamp is the number of seconds since January 1, 1970.) head (optional): The client's 435// relative heading or direction of travel. Specify the direction of travel as degrees from 0 through 360, 436// counting clockwise relative to true north. Specify this key only if the sp key is nonzero. sp (optional): 437// The horizontal velocity (speed), in meters per second, that the client device is traveling. alt (optional): 438// The altitude of the client device, in meters. are (optional): The radius, in meters, that specifies the 439// vertical accuracy of the coordinates. Specify this key only if you specify the alt key. Although many of the 440// keys are optional, the more information that you provide, the more accurate the location results are. 441// Although optional, you are encouraged to always specify the user's geographical location. Providing the 442// location is especially important if the client's IP address does not accurately reflect the user's physical 443// location (for example, if the client uses VPN). For optimal results, you should include this header and the 444// X-MSEdge-ClientIP header, but at a minimum, you should include this header. 445// aspect - filter images by the following aspect ratios. All: Do not filter by aspect.Specifying this value is 446// the same as not specifying the aspect parameter. Square: Return images with standard aspect ratio. Wide: 447// Return images with wide screen aspect ratio. Tall: Return images with tall aspect ratio. 448// colorParameter - filter images by the following color options. ColorOnly: Return color images. Monochrome: 449// Return black and white images. Return images with one of the following dominant colors: Black, Blue, Brown, 450// Gray, Green, Orange, Pink, Purple, Red, Teal, White, Yellow 451// countryCode - a 2-character country code of the country where the results come from. For a list of possible 452// values, see [Market 453// Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes). 454// If you set this parameter, you must also specify the 455// [Accept-Language](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#acceptlanguage) 456// header. Bing uses the first supported language it finds from the languages list, and combine that language 457// with the country code that you specify to determine the market to return results for. If the languages list 458// does not include a supported language, Bing finds the closest language and market that supports the request, 459// or it may use an aggregated or default market for the results instead of a specified one. You should use 460// this query parameter and the Accept-Language query parameter only if you specify multiple languages; 461// otherwise, you should use the mkt and setLang query parameters. This parameter and the 462// [mkt](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#mkt) query 463// parameter are mutually exclusive—do not specify both. 464// count - the number of images to return in the response. The actual number delivered may be less than 465// requested. The default is 35. The maximum value is 150. You use this parameter along with the offset 466// parameter to page results.For example, if your user interface displays 20 images per page, set count to 20 467// and offset to 0 to get the first page of results.For each subsequent page, increment offset by 20 (for 468// example, 0, 20, 40). Use this parameter only with the Image Search API.Do not specify this parameter when 469// calling the Insights, Trending Images, or Web Search APIs. 470// freshness - filter images by the following discovery options. Day: Return images discovered by Bing within 471// the last 24 hours. Week: Return images discovered by Bing within the last 7 days. Month: Return images 472// discovered by Bing within the last 30 days. 473// height - filter images that have the specified height, in pixels. You may use this filter with the size 474// filter to return small images that have a height of 150 pixels. 475// ID - an ID that uniquely identifies an image. Use this parameter to ensure that the specified image is the 476// first image in the list of images that Bing returns. The 477// [Image](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#image) 478// object's imageId field contains the ID that you set this parameter to. 479// imageContent - filter images by the following content types. Face: Return images that show only a person's 480// face. Portrait: Return images that show only a person's head and shoulders. 481// imageType - filter images by the following image types. AnimatedGif: Return only animated GIFs. Clipart: 482// Return only clip art images. Line: Return only line drawings. Photo: Return only photographs(excluding line 483// drawings, animated Gifs, and clip art). Shopping: Return only images that contain items where Bing knows of 484// a merchant that is selling the items. This option is valid in the en - US market only.Transparent: Return 485// only images with a transparent background. 486// license - filter images by the following license types. All: Do not filter by license type.Specifying this 487// value is the same as not specifying the license parameter. Any: Return images that are under any license 488// type. The response doesn't include images that do not specify a license or the license is unknown. Public: 489// Return images where the creator has waived their exclusive rights, to the fullest extent allowed by law. 490// Share: Return images that may be shared with others. Changing or editing the image might not be allowed. 491// Also, modifying, sharing, and using the image for commercial purposes might not be allowed. Typically, this 492// option returns the most images. ShareCommercially: Return images that may be shared with others for personal 493// or commercial purposes. Changing or editing the image might not be allowed. Modify: Return images that may 494// be modified, shared, and used. Changing or editing the image might not be allowed. Modifying, sharing, and 495// using the image for commercial purposes might not be allowed. ModifyCommercially: Return images that may be 496// modified, shared, and used for personal or commercial purposes. Typically, this option returns the fewest 497// images. For more information about these license types, see [Filter Images By License 498// Type](http://go.microsoft.com/fwlink/?LinkId=309768). 499// market - the market where the results come from. Typically, mkt is the country where the user is making the 500// request from. However, it could be a different country if the user is not located in a country where Bing 501// delivers results. The market must be in the form <language code>-<country code>. For example, en-US. The 502// string is case insensitive. For a list of possible market values, see [Market 503// Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes). 504// NOTE: If known, you are encouraged to always specify the market. Specifying the market helps Bing route the 505// request and return an appropriate and optimal response. If you specify a market that is not listed in 506// [Market 507// Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes), 508// Bing uses a best fit market code based on an internal mapping that is subject to change. This parameter and 509// the [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#cc) query 510// parameter are mutually exclusive—do not specify both. 511// maxFileSize - filter images that are less than or equal to the specified file size. The maximum file size 512// that you may specify is 520,192 bytes. If you specify a larger value, the API uses 520,192. It is possible 513// that the response may include images that are slightly larger than the specified maximum. You may specify 514// this filter and minFileSize to filter images within a range of file sizes. 515// maxHeight - filter images that have a height that is less than or equal to the specified height. Specify the 516// height in pixels. You may specify this filter and minHeight to filter images within a range of heights. This 517// filter and the height filter are mutually exclusive. 518// maxWidth - filter images that have a width that is less than or equal to the specified width. Specify the 519// width in pixels. You may specify this filter and maxWidth to filter images within a range of widths. This 520// filter and the width filter are mutually exclusive. 521// minFileSize - filter images that are greater than or equal to the specified file size. The maximum file size 522// that you may specify is 520,192 bytes. If you specify a larger value, the API uses 520,192. It is possible 523// that the response may include images that are slightly smaller than the specified minimum. You may specify 524// this filter and maxFileSize to filter images within a range of file sizes. 525// minHeight - filter images that have a height that is greater than or equal to the specified height. Specify 526// the height in pixels. You may specify this filter and maxHeight to filter images within a range of heights. 527// This filter and the height filter are mutually exclusive. 528// minWidth - filter images that have a width that is greater than or equal to the specified width. Specify the 529// width in pixels. You may specify this filter and maxWidth to filter images within a range of widths. This 530// filter and the width filter are mutually exclusive. 531// offset - the zero-based offset that indicates the number of images to skip before returning images. The 532// default is 0. The offset should be less than 533// ([totalEstimatedMatches](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#totalestimatedmatches) 534// - count). Use this parameter along with the count parameter to page results. For example, if your user 535// interface displays 20 images per page, set count to 20 and offset to 0 to get the first page of results. For 536// each subsequent page, increment offset by 20 (for example, 0, 20, 40). It is possible for multiple pages to 537// include some overlap in results. To prevent duplicates, see 538// [nextOffset](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#nextoffset). 539// Use this parameter only with the Image API. Do not specify this parameter when calling the Trending Images 540// API or the Web Search API. 541// safeSearch - filter images for adult content. The following are the possible filter values. Off: May return 542// images with adult content. If the request is through the Image Search API, the response includes thumbnail 543// images that are clear (non-fuzzy). However, if the request is through the Web Search API, the response 544// includes thumbnail images that are pixelated (fuzzy). Moderate: If the request is through the Image Search 545// API, the response doesn't include images with adult content. If the request is through the Web Search API, 546// the response may include images with adult content (the thumbnail images are pixelated (fuzzy)). Strict: Do 547// not return images with adult content. The default is Moderate. If the request comes from a market that 548// Bing's adult policy requires that safeSearch is set to Strict, Bing ignores the safeSearch value and uses 549// Strict. If you use the site: query operator, there is the chance that the response may contain adult content 550// regardless of what the safeSearch query parameter is set to. Use site: only if you are aware of the content 551// on the site and your scenario supports the possibility of adult content. 552// size - filter images by the following sizes. All: Do not filter by size. Specifying this value is the same 553// as not specifying the size parameter. Small: Return images that are less than 200x200 pixels. Medium: Return 554// images that are greater than or equal to 200x200 pixels but less than 500x500 pixels. Large: Return images 555// that are 500x500 pixels or larger. Wallpaper: Return wallpaper images. You may use this parameter along with 556// the height or width parameters. For example, you may use height and size to request small images that are 557// 150 pixels tall. 558// setLang - the language to use for user interface strings. Specify the language using the ISO 639-1 2-letter 559// language code. For example, the language code for English is EN. The default is EN (English). Although 560// optional, you should always specify the language. Typically, you set setLang to the same language specified 561// by mkt unless the user wants the user interface strings displayed in a different language. This parameter 562// and the 563// [Accept-Language](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#acceptlanguage) 564// header are mutually exclusive; do not specify both. A user interface string is a string that's used as a 565// label in a user interface. There are few user interface strings in the JSON response objects. Also, any 566// links to Bing.com properties in the response objects apply the specified language. 567// width - filter images that have the specified width, in pixels. You may use this filter with the size filter 568// to return small images that have a width of 150 pixels. 569func (client ImagesClient) Search(ctx context.Context, query string, acceptLanguage string, userAgent string, clientID string, clientIP string, location string, aspect ImageAspect, colorParameter ImageColor, countryCode string, count *int32, freshness Freshness, height *int32, ID string, imageContent ImageContent, imageType ImageType, license ImageLicense, market string, maxFileSize *int64, maxHeight *int64, maxWidth *int64, minFileSize *int64, minHeight *int64, minWidth *int64, offset *int64, safeSearch SafeSearch, size ImageSize, setLang string, width *int32) (result Images, err error) { 570 req, err := client.SearchPreparer(ctx, query, acceptLanguage, userAgent, clientID, clientIP, location, aspect, colorParameter, countryCode, count, freshness, height, ID, imageContent, imageType, license, market, maxFileSize, maxHeight, maxWidth, minFileSize, minHeight, minWidth, offset, safeSearch, size, setLang, width) 571 if err != nil { 572 err = autorest.NewErrorWithError(err, "imagesearch.ImagesClient", "Search", nil, "Failure preparing request") 573 return 574 } 575 576 resp, err := client.SearchSender(req) 577 if err != nil { 578 result.Response = autorest.Response{Response: resp} 579 err = autorest.NewErrorWithError(err, "imagesearch.ImagesClient", "Search", resp, "Failure sending request") 580 return 581 } 582 583 result, err = client.SearchResponder(resp) 584 if err != nil { 585 err = autorest.NewErrorWithError(err, "imagesearch.ImagesClient", "Search", resp, "Failure responding to request") 586 } 587 588 return 589} 590 591// SearchPreparer prepares the Search request. 592func (client ImagesClient) SearchPreparer(ctx context.Context, query string, acceptLanguage string, userAgent string, clientID string, clientIP string, location string, aspect ImageAspect, colorParameter ImageColor, countryCode string, count *int32, freshness Freshness, height *int32, ID string, imageContent ImageContent, imageType ImageType, license ImageLicense, market string, maxFileSize *int64, maxHeight *int64, maxWidth *int64, minFileSize *int64, minHeight *int64, minWidth *int64, offset *int64, safeSearch SafeSearch, size ImageSize, setLang string, width *int32) (*http.Request, error) { 593 queryParameters := map[string]interface{}{ 594 "q": autorest.Encode("query", query), 595 } 596 if len(string(aspect)) > 0 { 597 queryParameters["aspect"] = autorest.Encode("query", aspect) 598 } 599 if len(string(colorParameter)) > 0 { 600 queryParameters["color"] = autorest.Encode("query", colorParameter) 601 } 602 if len(countryCode) > 0 { 603 queryParameters["cc"] = autorest.Encode("query", countryCode) 604 } 605 if count != nil { 606 queryParameters["count"] = autorest.Encode("query", *count) 607 } 608 if len(string(freshness)) > 0 { 609 queryParameters["freshness"] = autorest.Encode("query", freshness) 610 } 611 if height != nil { 612 queryParameters["height"] = autorest.Encode("query", *height) 613 } 614 if len(ID) > 0 { 615 queryParameters["id"] = autorest.Encode("query", ID) 616 } 617 if len(string(imageContent)) > 0 { 618 queryParameters["imageContent"] = autorest.Encode("query", imageContent) 619 } 620 if len(string(imageType)) > 0 { 621 queryParameters["imageType"] = autorest.Encode("query", imageType) 622 } 623 if len(string(license)) > 0 { 624 queryParameters["license"] = autorest.Encode("query", license) 625 } 626 if len(market) > 0 { 627 queryParameters["mkt"] = autorest.Encode("query", market) 628 } 629 if maxFileSize != nil { 630 queryParameters["maxFileSize"] = autorest.Encode("query", *maxFileSize) 631 } 632 if maxHeight != nil { 633 queryParameters["maxHeight"] = autorest.Encode("query", *maxHeight) 634 } 635 if maxWidth != nil { 636 queryParameters["maxWidth"] = autorest.Encode("query", *maxWidth) 637 } 638 if minFileSize != nil { 639 queryParameters["minFileSize"] = autorest.Encode("query", *minFileSize) 640 } 641 if minHeight != nil { 642 queryParameters["minHeight"] = autorest.Encode("query", *minHeight) 643 } 644 if minWidth != nil { 645 queryParameters["minWidth"] = autorest.Encode("query", *minWidth) 646 } 647 if offset != nil { 648 queryParameters["offset"] = autorest.Encode("query", *offset) 649 } 650 if len(string(safeSearch)) > 0 { 651 queryParameters["safeSearch"] = autorest.Encode("query", safeSearch) 652 } 653 if len(string(size)) > 0 { 654 queryParameters["size"] = autorest.Encode("query", size) 655 } 656 if len(setLang) > 0 { 657 queryParameters["setLang"] = autorest.Encode("query", setLang) 658 } 659 if width != nil { 660 queryParameters["width"] = autorest.Encode("query", *width) 661 } 662 663 preparer := autorest.CreatePreparer( 664 autorest.AsGet(), 665 autorest.WithBaseURL(client.BaseURI), 666 autorest.WithPath("/images/search"), 667 autorest.WithQueryParameters(queryParameters), 668 autorest.WithHeader("X-BingApis-SDK", "true")) 669 if len(acceptLanguage) > 0 { 670 preparer = autorest.DecoratePreparer(preparer, 671 autorest.WithHeader("Accept-Language", autorest.String(acceptLanguage))) 672 } 673 if len(userAgent) > 0 { 674 preparer = autorest.DecoratePreparer(preparer, 675 autorest.WithHeader("User-Agent", autorest.String(userAgent))) 676 } 677 if len(clientID) > 0 { 678 preparer = autorest.DecoratePreparer(preparer, 679 autorest.WithHeader("X-MSEdge-ClientID", autorest.String(clientID))) 680 } 681 if len(clientIP) > 0 { 682 preparer = autorest.DecoratePreparer(preparer, 683 autorest.WithHeader("X-MSEdge-ClientIP", autorest.String(clientIP))) 684 } 685 if len(location) > 0 { 686 preparer = autorest.DecoratePreparer(preparer, 687 autorest.WithHeader("X-Search-Location", autorest.String(location))) 688 } 689 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 690} 691 692// SearchSender sends the Search request. The method will close the 693// http.Response Body if it receives an error. 694func (client ImagesClient) SearchSender(req *http.Request) (*http.Response, error) { 695 return autorest.SendWithSender(client, req, 696 autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 697} 698 699// SearchResponder handles the response to the Search request. The method always 700// closes the http.Response Body. 701func (client ImagesClient) SearchResponder(resp *http.Response) (result Images, err error) { 702 err = autorest.Respond( 703 resp, 704 client.ByInspecting(), 705 azure.WithErrorUnlessStatusCode(http.StatusOK), 706 autorest.ByUnmarshallingJSON(&result), 707 autorest.ByClosing()) 708 result.Response = autorest.Response{Response: resp} 709 return 710} 711 712// Trending sends the trending request. 713// Parameters: 714// acceptLanguage - a comma-delimited list of one or more languages to use for user interface strings. The list 715// is in decreasing order of preference. For additional information, including expected format, see 716// [RFC2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). This header and the 717// [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#setlang) 718// query parameter are mutually exclusive; do not specify both. If you set this header, you must also specify 719// the [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#cc) query 720// parameter. To determine the market to return results for, Bing uses the first supported language it finds 721// from the list and combines it with the cc parameter value. If the list does not include a supported 722// language, Bing finds the closest language and market that supports the request or it uses an aggregated or 723// default market for the results. To determine the market that Bing used, see the BingAPIs-Market header. Use 724// this header and the cc query parameter only if you specify multiple languages. Otherwise, use the 725// [mkt](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#mkt) and 726// [setLang](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#setlang) 727// query parameters. A user interface string is a string that's used as a label in a user interface. There are 728// few user interface strings in the JSON response objects. Any links to Bing.com properties in the response 729// objects apply the specified language. 730// userAgent - the user agent originating the request. Bing uses the user agent to provide mobile users with an 731// optimized experience. Although optional, you are encouraged to always specify this header. The user-agent 732// should be the same string that any commonly used browser sends. For information about user agents, see [RFC 733// 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). The following are examples of user-agent 734// strings. Windows Phone: Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; 735// ARM; Touch; NOKIA; Lumia 822). Android: Mozilla / 5.0 (Linux; U; Android 2.3.5; en - us; SCH - I500 Build / 736// GINGERBREAD) AppleWebKit / 533.1 (KHTML; like Gecko) Version / 4.0 Mobile Safari / 533.1. iPhone: Mozilla / 737// 5.0 (iPhone; CPU iPhone OS 6_1 like Mac OS X) AppleWebKit / 536.26 (KHTML; like Gecko) Mobile / 10B142 738// iPhone4; 1 BingWeb / 3.03.1428.20120423. PC: Mozilla / 5.0 (Windows NT 6.3; WOW64; Trident / 7.0; Touch; 739// rv:11.0) like Gecko. iPad: Mozilla / 5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit / 537.51.1 (KHTML, 740// like Gecko) Version / 7.0 Mobile / 11A465 Safari / 9537.53 741// clientID - bing uses this header to provide users with consistent behavior across Bing API calls. Bing often 742// flights new features and improvements, and it uses the client ID as a key for assigning traffic on different 743// flights. If you do not use the same client ID for a user across multiple requests, then Bing may assign the 744// user to multiple conflicting flights. Being assigned to multiple conflicting flights can lead to an 745// inconsistent user experience. For example, if the second request has a different flight assignment than the 746// first, the experience may be unexpected. Also, Bing can use the client ID to tailor web results to that 747// client ID’s search history, providing a richer experience for the user. Bing also uses this header to help 748// improve result rankings by analyzing the activity generated by a client ID. The relevance improvements help 749// with better quality of results delivered by Bing APIs and in turn enables higher click-through rates for the 750// API consumer. IMPORTANT: Although optional, you should consider this header required. Persisting the client 751// ID across multiple requests for the same end user and device combination enables 1) the API consumer to 752// receive a consistent user experience, and 2) higher click-through rates via better quality of results from 753// the Bing APIs. Each user that uses your application on the device must have a unique, Bing generated client 754// ID. If you do not include this header in the request, Bing generates an ID and returns it in the 755// X-MSEdge-ClientID response header. The only time that you should NOT include this header in a request is the 756// first time the user uses your app on that device. Use the client ID for each Bing API request that your app 757// makes for this user on the device. Persist the client ID. To persist the ID in a browser app, use a 758// persistent HTTP cookie to ensure the ID is used across all sessions. Do not use a session cookie. For other 759// apps such as mobile apps, use the device's persistent storage to persist the ID. The next time the user uses 760// your app on that device, get the client ID that you persisted. Bing responses may or may not include this 761// header. If the response includes this header, capture the client ID and use it for all subsequent Bing 762// requests for the user on that device. If you include the X-MSEdge-ClientID, you must not include cookies in 763// the request. 764// clientIP - the IPv4 or IPv6 address of the client device. The IP address is used to discover the user's 765// location. Bing uses the location information to determine safe search behavior. Although optional, you are 766// encouraged to always specify this header and the X-Search-Location header. Do not obfuscate the address (for 767// example, by changing the last octet to 0). Obfuscating the address results in the location not being 768// anywhere near the device's actual location, which may result in Bing serving erroneous results. 769// location - a semicolon-delimited list of key/value pairs that describe the client's geographical location. 770// Bing uses the location information to determine safe search behavior and to return relevant local content. 771// Specify the key/value pair as <key>:<value>. The following are the keys that you use to specify the user's 772// location. lat (required): The latitude of the client's location, in degrees. The latitude must be greater 773// than or equal to -90.0 and less than or equal to +90.0. Negative values indicate southern latitudes and 774// positive values indicate northern latitudes. long (required): The longitude of the client's location, in 775// degrees. The longitude must be greater than or equal to -180.0 and less than or equal to +180.0. Negative 776// values indicate western longitudes and positive values indicate eastern longitudes. re (required): The 777// radius, in meters, which specifies the horizontal accuracy of the coordinates. Pass the value returned by 778// the device's location service. Typical values might be 22m for GPS/Wi-Fi, 380m for cell tower triangulation, 779// and 18,000m for reverse IP lookup. ts (optional): The UTC UNIX timestamp of when the client was at the 780// location. (The UNIX timestamp is the number of seconds since January 1, 1970.) head (optional): The client's 781// relative heading or direction of travel. Specify the direction of travel as degrees from 0 through 360, 782// counting clockwise relative to true north. Specify this key only if the sp key is nonzero. sp (optional): 783// The horizontal velocity (speed), in meters per second, that the client device is traveling. alt (optional): 784// The altitude of the client device, in meters. are (optional): The radius, in meters, that specifies the 785// vertical accuracy of the coordinates. Specify this key only if you specify the alt key. Although many of the 786// keys are optional, the more information that you provide, the more accurate the location results are. 787// Although optional, you are encouraged to always specify the user's geographical location. Providing the 788// location is especially important if the client's IP address does not accurately reflect the user's physical 789// location (for example, if the client uses VPN). For optimal results, you should include this header and the 790// X-MSEdge-ClientIP header, but at a minimum, you should include this header. 791// countryCode - a 2-character country code of the country where the results come from. This API supports only 792// the United States, Canada, Australia, and China markets. If you specify this query parameter, it must be set 793// to us, ca, au, or cn. If you set this parameter, you must also specify the Accept-Language header. Bing uses 794// the first supported language it finds from the languages list, and combine that language with the country 795// code that you specify to determine the market to return results for. If the languages list does not include 796// a supported language, Bing finds the closest language and market that supports the request, or it may use an 797// aggregated or default market for the results instead of a specified one. You should use this query parameter 798// and the Accept-Language query parameter only if you specify multiple languages; otherwise, you should use 799// the mkt and setLang query parameters. This parameter and the mkt query parameter are mutually exclusive—do 800// not specify both. 801// market - the market where the results come from. Typically, mkt is the country where the user is making the 802// request from. However, it could be a different country if the user is not located in a country where Bing 803// delivers results. The market must be in the form <language code>-<country code>. For example, en-US. The 804// string is case insensitive. For a list of possible market values, see [Market 805// Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes). 806// NOTE: If known, you are encouraged to always specify the market. Specifying the market helps Bing route the 807// request and return an appropriate and optimal response. If you specify a market that is not listed in 808// [Market 809// Codes](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes), 810// Bing uses a best fit market code based on an internal mapping that is subject to change. This parameter and 811// the [cc](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#cc) query 812// parameter are mutually exclusive—do not specify both. 813// safeSearch - filter images for adult content. The following are the possible filter values. Off: May return 814// images with adult content. If the request is through the Image Search API, the response includes thumbnail 815// images that are clear (non-fuzzy). However, if the request is through the Web Search API, the response 816// includes thumbnail images that are pixelated (fuzzy). Moderate: If the request is through the Image Search 817// API, the response doesn't include images with adult content. If the request is through the Web Search API, 818// the response may include images with adult content (the thumbnail images are pixelated (fuzzy)). Strict: Do 819// not return images with adult content. The default is Moderate. If the request comes from a market that 820// Bing's adult policy requires that safeSearch is set to Strict, Bing ignores the safeSearch value and uses 821// Strict. If you use the site: query operator, there is the chance that the response may contain adult content 822// regardless of what the safeSearch query parameter is set to. Use site: only if you are aware of the content 823// on the site and your scenario supports the possibility of adult content. 824// setLang - the language to use for user interface strings. Specify the language using the ISO 639-1 2-letter 825// language code. For example, the language code for English is EN. The default is EN (English). Although 826// optional, you should always specify the language. Typically, you set setLang to the same language specified 827// by mkt unless the user wants the user interface strings displayed in a different language. This parameter 828// and the 829// [Accept-Language](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#acceptlanguage) 830// header are mutually exclusive; do not specify both. A user interface string is a string that's used as a 831// label in a user interface. There are few user interface strings in the JSON response objects. Also, any 832// links to Bing.com properties in the response objects apply the specified language. 833func (client ImagesClient) Trending(ctx context.Context, acceptLanguage string, userAgent string, clientID string, clientIP string, location string, countryCode string, market string, safeSearch SafeSearch, setLang string) (result TrendingImages, err error) { 834 req, err := client.TrendingPreparer(ctx, acceptLanguage, userAgent, clientID, clientIP, location, countryCode, market, safeSearch, setLang) 835 if err != nil { 836 err = autorest.NewErrorWithError(err, "imagesearch.ImagesClient", "Trending", nil, "Failure preparing request") 837 return 838 } 839 840 resp, err := client.TrendingSender(req) 841 if err != nil { 842 result.Response = autorest.Response{Response: resp} 843 err = autorest.NewErrorWithError(err, "imagesearch.ImagesClient", "Trending", resp, "Failure sending request") 844 return 845 } 846 847 result, err = client.TrendingResponder(resp) 848 if err != nil { 849 err = autorest.NewErrorWithError(err, "imagesearch.ImagesClient", "Trending", resp, "Failure responding to request") 850 } 851 852 return 853} 854 855// TrendingPreparer prepares the Trending request. 856func (client ImagesClient) TrendingPreparer(ctx context.Context, acceptLanguage string, userAgent string, clientID string, clientIP string, location string, countryCode string, market string, safeSearch SafeSearch, setLang string) (*http.Request, error) { 857 queryParameters := map[string]interface{}{} 858 if len(countryCode) > 0 { 859 queryParameters["cc"] = autorest.Encode("query", countryCode) 860 } 861 if len(market) > 0 { 862 queryParameters["mkt"] = autorest.Encode("query", market) 863 } 864 if len(string(safeSearch)) > 0 { 865 queryParameters["safeSearch"] = autorest.Encode("query", safeSearch) 866 } 867 if len(setLang) > 0 { 868 queryParameters["setLang"] = autorest.Encode("query", setLang) 869 } 870 871 preparer := autorest.CreatePreparer( 872 autorest.AsGet(), 873 autorest.WithBaseURL(client.BaseURI), 874 autorest.WithPath("/images/trending"), 875 autorest.WithQueryParameters(queryParameters), 876 autorest.WithHeader("X-BingApis-SDK", "true")) 877 if len(acceptLanguage) > 0 { 878 preparer = autorest.DecoratePreparer(preparer, 879 autorest.WithHeader("Accept-Language", autorest.String(acceptLanguage))) 880 } 881 if len(userAgent) > 0 { 882 preparer = autorest.DecoratePreparer(preparer, 883 autorest.WithHeader("User-Agent", autorest.String(userAgent))) 884 } 885 if len(clientID) > 0 { 886 preparer = autorest.DecoratePreparer(preparer, 887 autorest.WithHeader("X-MSEdge-ClientID", autorest.String(clientID))) 888 } 889 if len(clientIP) > 0 { 890 preparer = autorest.DecoratePreparer(preparer, 891 autorest.WithHeader("X-MSEdge-ClientIP", autorest.String(clientIP))) 892 } 893 if len(location) > 0 { 894 preparer = autorest.DecoratePreparer(preparer, 895 autorest.WithHeader("X-Search-Location", autorest.String(location))) 896 } 897 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 898} 899 900// TrendingSender sends the Trending request. The method will close the 901// http.Response Body if it receives an error. 902func (client ImagesClient) TrendingSender(req *http.Request) (*http.Response, error) { 903 return autorest.SendWithSender(client, req, 904 autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 905} 906 907// TrendingResponder handles the response to the Trending request. The method always 908// closes the http.Response Body. 909func (client ImagesClient) TrendingResponder(resp *http.Response) (result TrendingImages, err error) { 910 err = autorest.Respond( 911 resp, 912 client.ByInspecting(), 913 azure.WithErrorUnlessStatusCode(http.StatusOK), 914 autorest.ByUnmarshallingJSON(&result), 915 autorest.ByClosing()) 916 result.Response = autorest.Response{Response: resp} 917 return 918} 919