[英]How to use Azure API for FHIR Server without any authorization token
[英]How to use azure translator with authorization token?
我想將 azure 翻譯服務與授權令牌一起使用。 有很多資源解釋了如何使用訂閱密鑰進行操作,但我找不到任何解釋授權令牌使用的資源。 我可以獲得授權令牌,但是當我使用它發送請求時,響應狀態碼是 401。這就是我發送請求的方式:
curl POST 'https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=es' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer token' \
--data-raw '[{'\''Text'\'':'\''Hello World!'\''}]'
如果要使用認證令牌調用文本翻譯API,請參考以下步驟
https://api.cognitive.microsoft.com/sts/v1.0/issueToken
curl -v -X POST \
"https://YOUR-REGION.api.cognitive.microsoft.com/sts/v1.0/issueToken" \
-H "Content-type: application/x-www-form-urlencoded" \
-H "Content-length: 0" \
-H "Ocp-Apim-Subscription-Key: YOUR_SUBSCRIPTION_KEY"
此外,請注意身份驗證令牌的有效期為 10 分鍾。 多次調用 Translator 時應重復使用該令牌。 但是,如果您的程序在較長時間內向 Translator 發出請求,則您的程序必須定期(例如,每 8 分鍾)請求一個新的訪問令牌。
curl -X POST 'https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=de' \
-H 'Authorization: Bearer YOUR_AUTH_TOKEN' \
-H 'Content-Type: application/json' \
--data-raw '[{ "text": "How much for the cup of coffee?" }]' | json_pp
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.