2017-02-16 36 views
2

我試圖使用推薦curl方法用於文本分析的微軟認知API:微軟認知API令牌不從<a href="https://www.microsoft.com/cognitive-services/en-us/text-analytics-api" rel="nofollow noreferrer">their documentation</a>工作

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

注:是的,我實現與顯示關鍵的安全問題,但我必須重新生成的感謝。

回答

2

有三個問題你的要求:

  • Content-Type頭應該是application/json。這可能是一個複製粘貼錯誤。
  • Ocp-Apim-Subscription-Key標頭值必須是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":[]} 
相關問題