dongquxiao8545 2016-09-13 10:16
浏览 36

用于PHP的Bing Image搜索API v5.0示例

I'm trying, without success, to get some results using Bing's Image search API without HTTP/Request2.php component (as used in the official examples).

I understand that the only two required parameters to make a very primitive call are q which is the query string and the subscription key. The key must be sent using headers. After looking around I found this very simple example to send headers with PHP:

$sURL = "https://api.cognitive.microsoft.com/bing/v5.0/images/search?q=cats";
$aHTTP = array(
    'Ocp-Apim-Subscription-Key' => 'xxxxxxx',
);
$context = stream_context_create($aHTTP);
$contents = file_get_contents($sURL, false, $context);

echo $contents;

But it does not output anything. Would you kindly help me with a very basic example of use of Bing's API?

  • 写回答

3条回答 默认 最新

  • douniwan_0025 2016-09-13 10:51
    关注

    Try using cURL

    $sURL = "https://api.cognitive.microsoft.com/bing/v5.0/images/search?q=cats";
    $key = "xxxxxxx";
    
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $sURL); 
    curl_setopt($ch, CURLOPT_TIMEOUT, '1'); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 'ocp-apim-subscription-key:$key');
    $content = curl_exec($ch);
    
    echo $content;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法