gpt4 book ai didi

php - Bing Web 搜索 API v5.0 基础知识

转载 作者:行者123 更新时间:2023-12-03 05:57:24 25 4
gpt4 key购买 nike

我尝试从基础知识开始,并获取从 Azure API for Bing 网络搜索返回的任何结果。我已经通过他们的沙箱成功产生结果API Testing Console ,但在现场环境中我一事无成。我熟悉previous SO posts在 Bing API 上,但这些响应已经有 4 或 5 年历史了,并且似乎没有引用当前的 API。

Azure docs请引用将 Ocp-Apim-Subscription-Key header 设置为 API key 。当微软自己的文档appears very dated出现在某些地方时,这是令人沮丧的。我确信我是第一个提示这一点的人!

注意:在写这个问题时,我得到了一个可行的解决方案。我将继续发布带有工作代码的答案。 Bing API v5.0 的示例似乎很少。

最佳答案

我找到的工作代码有望帮助您入门:

$accountKey = 'the_account_key';

$url = 'https://api.cognitive.microsoft.com/bing/v5.0/search?q=billgates&count=10&offset=0&mkt=en-us&safesearch=Moderate';

// Create a stream
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Ocp-Apim-Subscription-Key: $accountKey"
)
);
$context = stream_context_create($opts);

// Open the file using the HTTP headers set above
$file = file_get_contents($url, false, $context);

echo $file;

这是原始响应。您需要解码 JSON 并使用该对象:

$jsonobj = json_decode($file);

关于php - Bing Web 搜索 API v5.0 基础知识,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39008551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com