Bing API相关搜索

发布时间:2025-08-11 05:52

使用财经搜索引擎如Bing Finance查询详细数据。 #生活技巧# #个人理财技巧# #金融资讯获取#

提问于 2019-04-29 18:14:00

回答 1查看 349关注 0票数 0

如何让相关搜索包含在Bing search API的响应中?

根据这里的文档,我正在尝试应用具有值RelatedSearches的responseFilter:https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-web-api-v7-reference#relatedsearchanswer

下面是我的代码,基于Bing的示例。我将"&responseFilter=RelatedSearches“添加到由file_get_contents()获取的URL中。

我得到的错误是:

代码语言:javascript

运行

复制

PHP Warning: file_get_contents(https://api.cognitive.microsoft.com/bing/v7.0/search?responseFilter=RelatedSearches&q=iphone+case): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden

显然,我的应用是错误的。我可以做些什么来使其正常工作?

代码语言:javascript

运行

复制

<?php $accessKey = 'abc123'; $endpoint = 'https://api.cognitive.microsoft.com/bing/v7.0/search'; $term = 'burrito recipe'; function BingWebSearch ($url, $key, $query) { $headers = "Ocp-Apim-Subscription-Key: $key\r\n"; $options = array ('http' => array ( 'header' => $headers, 'method' => 'GET')); $context = stream_context_create($options); $result = file_get_contents($url . "?q=" . urlencode($query) . "&responseFilter=RelatedSearches", false, $context); $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); } if (strlen($accessKey) == 32) { print "Searching the Web for: " . $term . "\n"; list($headers, $json) = BingWebSearch($endpoint, $accessKey, $term); print "\nRelevant Headers:\n\n"; foreach ($headers as $k => $v) { print $k . ": " . $v . "\n"; } print "\nJSON Response:\n\n"; echo json_encode(json_decode($json), JSON_PRETTY_PRINT); } else { print("Invalid Bing Search API subscription key!\n"); print("Please paste yours into the source code.\n"); } ?>

EN

Stack Overflow用户

发布于 2019-04-29 18:21:16

票数 0

EN

页面原文内容由

Stack Overflow

提供。腾讯云小微IT领域专用引擎提供翻译支持

原文链接:

https://stackoverflow.com/questions/55901233

复制

相关文章

相似问题

网址:Bing API相关搜索 https://klqsh.com/news/view/136506

相关内容

Release notes for Bing Custom Web Search API
Web Search API
Microsoft Bing
27年前,大S徐熙媛与具俊晔的甜蜜互动,真是令人怀念!Bing Bing Bing!
Learn to use Bing search operators
Bing Tests Related Search Interfaces
相关关键词搜索,通过SmallSEOTools免费在线关键字工具
Bing Search APIs Retiring on August 11, 2025
Bing Search Tests Zoomable & Sticky Related Searches
How To See All Bing Related Searches

随便看看