azure-cognitive-services - Microsoft 认知 API token 不起作用

标签 azure-cognitive-services

我正在尝试使用 their documentation 中推荐的 curl 方法,使用 Microsoft 认知 API 进行文本分析。 :

curl -v -X POST "https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment" -H "Content-Type: application/jscp-Apim-Subscription-Key: {bc94cba9b84748ebb2f2b79a28ee3450}" --data-ascii "{I had a wonderful experience! The rooms were wonderful and the staff were helpful.}" 

但我回来了:

{ "statusCode": 401, "message": "Access denied due to invalid subscription key. Make sure to provide a valid key for an active subscription." }

我还尝试删除要分析的标记和文本周围的 {}。我在这里做错了什么?

enter image description here

注意:是的,我意识到显示 key 存在安全问题,但我已重新生成,谢谢。

最佳答案

您的请求存在三个问题:

  • Content-Type header 应为 application/json。这可能是复制粘贴错误。
  • Ocp-Apim-Subscription-Key header 值必须是不带大括号的 API。这就是导致 401 错误的原因。
  • 正文必须是特定格式的 JSON。您可以找到架构 here .

这是重写的请求:

curl -v "https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: $OXFORD_TEXT_KEY" --data-ascii '{"documents":[{"language":"en","id":"1234","text":"I had a wonderful experience! The rooms were wonderful and the staff were helpful."}]}' 

这应该导致:

{"documents":[{"score":0.9750894,"id":"1234"}],"errors":[]}

关于azure-cognitive-services - Microsoft 认知 API token 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42263899/

相关文章:

azure - 应用最新的运行时更新来改进 QnA Maker 结果 - 需要重新迁移吗?

c# - QnaMakerDialog 尝试次数过多

c# - Azure 文本转语音 API : only mono output formats (no stereo formats) available?

azure - MS 文本分析认知服务 : how to work with local database?

c# - 我应该使用哪个工具以 Microsoft Speaker Recognition API 支持的格式录制音频(或转换录制的音频)?

azure-functions - 如何将 Azure 认知服务语音音频输出写入 Azure Blob?

javascript - 限制 Azure API 在我的域中的使用

Azure 翻译服务的 JSON 反序列化错误

azure-language-understanding - 短语列表中的 "The values are interchangable"选项如何在 LUIS 中工作?