Does the Bing Search API
(images) demo key have any limitations? On the test page (https://azure.microsoft.com/ru-ru/services/cognitive-services/bing-image-search-api/), the search phrase produces a lot of results, but in my script there are no results at all. Here is the script itself:
function getImages($query) {
$query = str_replace(' ', '+', $query);
$url = 'https://api.cognitive.microsoft.com/bing/v7.0/images/search?q=' . $query . '&safesearch=strict';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_TIMEOUT, '1');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: multipart/form-data',
'Ocp-Apim-Subscription-Key: KEY'
));
$result = curl_exec($curl);
$result = json_decode($result, true);
return $result['value'];
}
Reason:
The value of
CURLOPT_TIMEOUT
too short.Please modify the value of
CURLOPT_TIMEOUT
to>=5
, and then continue the test.In postman, the sample request need 1.074s. I change the value of
CURLOPT_TIMEOUT
. It works for me.Code:
Run it online.
Open the site to test code online. Paste code, and run it.
Then you can check the result between postman and online.