以下代码未返回 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, $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);