draw62188 2013-01-18 09:35
浏览 74
已采纳

bing api搜索[关闭]

I am trying to search some images with bing api key. I wrote this code but it don't work, and it not return some error. I think it is an api error...can you help me?

$accountKey = 's+s/s=';
$rootUri = 'https://api.datamarket.azure.com/Bing/Search';

// Get the query. Default to 'sushi'.
$query = ($_GET['q']) ? $_GET['q'] : 'sushi';

// Get the service operation. Default to Web.
$serviceOp = ($_GET['sop']) ? $_GET['sop'] : 'Web';

// Get the market. Default to en-us.
$market = ($_GET['market']) ? $_GET['market'] : 'en-us';

$ServiceRootURL =  'https://api.datamarket.azure.com/Bing/SearchWeb/';  
$WebSearchURL = $ServiceRootURL . 'Web?$format=json&Query=';

$request = $WebSearchURL . urlencode( '\'' . $query. '\'');
echo $request;
//$requestUri = "$rootUri/$serviceOp?\$format=json&Query=$query&Market=$market";

$process = curl_init($request);
curl_setopt($process, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($process, CURLOPT_USERPWD,  $accountKey . ":" . $accountKey);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($process);
$jsonobj = json_decode($response);
echo "<br>Ris = ".$jsonobj;
  • 写回答

1条回答 默认 最新

  • dongpiao9078 2013-01-18 09:46
    关注

    I just jump into the documentation and you can use file_get_contents instead of cURL.

    <?php
    $accountKey = 'xxxxx';
    
    $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'] : 'sushi';
    $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 . 'Web?$format=json&Query=';
    
    $request = $WebSearchURL . urlencode( '\'' . $query. '\'');
    
    // Get the response from Bing.
    $response = file_get_contents($request, 0, $context);
    var_dump($response);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应