我已阅读此帖:Bing search API and Azure
我使用以下代码来模仿它:
<?php
if (isset($_GET['bingquery'])){
// Replace this value with your account key
$accountKey = '***myaccountkey***';
$WebSearchURL = 'https://api.datamarket.azure.com/Bing/Search/v1/' + 'News?$format=json&Query=';
$cred = sprintf('Authorization: Basic %s', base64_encode($accountKey . ":" . $accountKey) );
$context = stream_context_create(array(
'http' => array(
'header' => $cred
)
));
$request = $WebSearchURL . urlencode( '\'' . $_GET["bingquery"] . '\'');
$response = file_get_contents($request, 0, $context);
echo $response;
}
?>
我的AJAX电话是:
var bingquery = "bingquery=" + $('#query').val();
$.ajax({
url: "bingsearch.php",
method: "get",
dataType: "json",
data: bingquery,
success: function(jsondata){
console.log(jsondata);
}
});
但是,我仍然无法从Bing搜索中获取JSON格式数据,有什么建议吗?非常感谢你的帮助!