gpt4 book ai didi

microsoft-cognitive - Microsoft Cognitive API 的正确 key

转载 作者:行者123 更新时间:2023-12-01 00:40:33 26 4
gpt4 key购买 nike

我目前正在尝试对 MS 认知服务 Bing 搜索 API 进行新闻搜索。我已经阅读了很多文档,但似乎被卡住了。

这是我正在使用的代码:

$url = 'https://bingapis.azure-api.net/api/v5/news/search?q=microsoft&mkt=en-us';
$key = '{MY KEY}';
$request_headers = array();
$request_headers[] = 'Ocp-Apim-Subscription-Key: '. $key;
$request_headers[] = 'User-Agent: mozilla';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
$data = curl_exec($ch);
curl_close($ch);
echo $data;

此代码返回以下结果:
{ "statusCode": 401, "message": "Access denied due to invalid subscription key. Make sure to provide a valid key for an active subscription." }

当我从站点上的 API Explorer 得到相同的结果时,我认为问题出在我的 key 上,而不是我的代码上。但这是认知服务为我的订阅提供的 key ,可在 https://www.microsoft.com/cognitive-services/en-us/subscriptions 上找到。 (登录时)。

如果这不是正确的 key ,我应该使用什么?

最佳答案

我在 Microsoft 的认知服务团队工作。如果您在 6 月 22 日之后生成订阅 key (或更新您的 key )并且当前正在使用 https://bingapis.azure-api.net/api/v5/,则您可能会遇到 Bing API 的这个问题。基本 URI。

更新以使用新订阅 key 时,您必须更新您的应用程序以使用 https://api.cognitive.microsoft.com/bing/v5.0/基本 URI。

此外,如果您使用 Bing API 的 API 引用,您可以尝试以下链接,这些链接应该适用于新 key 。

对给您带来的不便深表歉意,并感谢您报告问题 - 我们正在更新链接。

关于microsoft-cognitive - Microsoft Cognitive API 的正确 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37969050/

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