【问题标题】:bing search api php filter必应搜索 api php 过滤器
【发布时间】:2014-06-16 17:14:45
【问题描述】:

我正在使用以下 php 连接到 bing api: 如何添加过滤器(尺寸:小)? 该代码来自 bing 文档,它工作正常。 我正在使用此代码连接到 bing 并将响应重定向到 iOS 应用程序。 请帮忙...

 <?php
{

$accountKey = ‘XXXXXXXXX’;
$auth = base64_encode("$accountKey:$accountKey");
$data = array(
  'http'            => array(
  'request_fulluri' => true,
  'ignore_errors'   => true,
  'header'          => "Authorization: Basic " . $auth));
$context   = stream_context_create($data);
$query     = isset($_GET['q']) ? $_GET['q'] : htmlspecialchars($_GET["searchtext"]);
$serviceOp = isset($_GET['sop']) ? $_GET['sop'] : 'Web';
$market    = isset($_GET['market']) ? $_GET['market'] : 'en-us';
$ServiceRootURL = 'https://api.datamarket.azure.com/Bing/Search/';  
$WebSearchURL   = $ServiceRootURL . 'Image?$format=json&Image.Filters=+filterui:imagesize-large+filterui:photo-photo+filterui:face-face&Query=';
$request = $WebSearchURL . urlencode( '\'' . $query. '\'') ;
// Get the response from Bing.
$response = file_get_contents($request, 0, $context);                    
                    $jsonobj = json_decode($response);

                   // echo('<ul ID="resultList">');
header('Content-Type: application/json');

            echo($response);
?>

【问题讨论】:

    标签: php api filter bing


    【解决方案1】:

    首先从 $WebSearchURL 变量中删除所有图像过滤器, 然后用这种方式添加你的图像过滤器:

    $request = $WebSearchURL . urlencode( '\'' . $query. '\'').'&ImageFilters=';
    $request = $request . urlencode( '\'' .'Size:Large+Face:Face'. '\'');
    

    希望它对你有用:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-23
      • 2011-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-11
      相关资源
      最近更新 更多