1

我收到400错误信息,如图图像的下方,当我用试试看链接http://docs.microsofttranslator.com/text-translate.html微软翻译API错误消息:接收的令牌是不正确的令牌类型

我使用的尝试翻译API从Azure Portal for Cognitive Services免费试用产生的访问密钥。

MS Azure Portal Link

我已经阅读MS支持博客,我试图在其中提到的所有建议。但每次,我都会收到400状态错误,如下所示。 有人可以帮我解决这个问题吗?

enter image description here

回答

1

你需要做一个POST请求得到一个访问令牌第一(文档here):

curl --header 'Ocp-Apim-Subscription-Key: <YOUR-API-KEY>' --data "" 'https://api.cognitive.microsoft.com/sts/v1.0/issueToken' 

,然后使用该令牌在Authorization头。 (appId已被弃用)。

curl -X GET --header 'Accept: application/xml' --header 'Authorization: Bearer <YOUR-TOKEN>' 'https://api.microsofttranslator.com/v2/http.svc/Translate?&text=this%20is%20my%20name&from=en&to=af' 
+0

@Sabyasachi,有帮助吗? –

+0

不,您无法从浏览器执行该调用,因为它是POST请求。你应该使用邮递员这样的工具。 https://www.getpostman.com/ –

+0

好吧...试试吧.... – Sabyasachi