Microsoft Cognitive API的正确密钥 [英] Correct Key for Microsoft Cognitive API

查看:116
本文介绍了Microsoft Cognitive API的正确密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用MS Cognitive Services Bing Search API进行新闻搜索.我已经阅读了许多文档,但似乎卡住了.

I am currently trying to do a News Search on the MS Cognitive Services Bing Search API. I have read many docs, but seem to be stuck.

这是我正在使用的代码:

Here is the code I'm using:

$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获得相同的结果时,我认为问题出在我的密钥,而不是我的代码.但这是Cognitive Services为我的订阅提供的密钥,如在 https:/上找到的那样/www.microsoft.com/cognitive-services/zh-CN/subscriptions (登录时).

As I get the same result from the API Explorer on the site, I think the problem is with my key, rather than my code. But this is the key supplied by Cognitive Services for my subscription, as found on https://www.microsoft.com/cognitive-services/en-us/subscriptions (when logged in).

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

If this is not the correct key, what should I be using?

推荐答案

我在Microsoft认知服务团队工作.如果您在6月22日之后生成了订阅密钥(或更新了密钥),并且当前正在使用

I'm on the Cognitive Service team at Microsoft. You may hit this issue for the Bing APIs if you generated your subscription keys after 22 June (or renewed your key) and are currently using the https://bingapis.azure-api.net/api/v5/ base URI.

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

When updating to use the new subscription keys, you must update your application to use the https://api.cognitive.microsoft.com/bing/v5.0/ base URI.

此外,如果您使用的是Bing API的API参考,则可以尝试以下链接,这些链接应与新密钥一起使用.

Additionally, If you were using the API Reference for Bing APIs, you can try the following links below which should work with the new keys.

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

Apologies for the inconvenience and thanks for reporting the issue- we are getting the link updated.

这篇关于Microsoft Cognitive API的正确密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆