如何显示Bing新闻API的50或100个结果
以下代码不会返回50条新闻结果。我正在使用如何显示Bing新闻API的50或100个结果,api,azure,search,bing,bing-news-search-api,Api,Azure,Search,Bing,Bing News Search Api,以下代码不会返回50条新闻结果。我正在使用 &count=50&offset=0但不工作 感谢您的帮助 $endpoint = 'https://api.cognitive.microsoft.com/bing/v7.0/news'; $term = $_GET['q']; $site = '(((site:aaa.com+OR+site:bbb.com)+OR+site:ccc.net)+OR+site:ddd.com)'; function BingNewsSearch ($url,
&count=50&offset=0
但不工作
感谢您的帮助
$endpoint = 'https://api.cognitive.microsoft.com/bing/v7.0/news';
$term = $_GET['q'];
$site = '(((site:aaa.com+OR+site:bbb.com)+OR+site:ccc.net)+OR+site:ddd.com)';
function BingNewsSearch ($url, $key, $query, $site) {
$headers = "Ocp-Apim-Subscription-Key: $key\r\n";
$options = array ('http' => array (
'header' => $headers,
'method' => 'GET' ));
// Perform the Web request and get the JSON response
$context = stream_context_create($options);
$result = file_get_contents($url . "?q=" .
urlencode($query).'+'.$site.'&cc=CR&setLang=es&count=50&offset=0', false,
$context);
// Extract Bing HTTP headers
$headers = array();
foreach ($http_response_header as $k => $v) {
$h = explode(":", $v, 2);
if (isset($h[1]))
if (preg_match("/^BingAPIs-/", $h[0]) || preg_match("/^X-MSEdge-/", $h[0]))
$headers[trim($h[0])] = trim($h[1]);
}
return array($headers, $result);
}
print "Searching news for: " . $term . "\n";
list($headers, $json) = BingNewsSearch($endpoint, $accessKey, $term, $site);
这里有几个问题。1) 端点的结尾应该有/search,2)您试图将结果限制在aaa、bbb、ccc和ddd域。你真的需要吗?3)使用mkt参数,而不是cc和setLang参数。而且,cc=CR似乎不是正确的值
您可以在此处查看受支持的市场:。您好!谢谢你的回答。嗯,谢谢你!我发现使用/news可以进行域限制,但使用/news/search不行。但是,计数和偏移仅适用于/news/search。。。。2) 是3)cc为我带来了更好的结果,文档中说:“如果语言列表中没有支持的语言,Bing会找到支持请求的最接近的语言和市场。”…“最接近的”对我来说很有用。再次感谢您的快速回复。