【问题标题】:Microsoft Translator API Error Message: The received token is of incorrect token typeMicrosoft Translator API 错误消息:收到的令牌的令牌类型不正确
【发布时间】:2017-05-29 15:55:12
【问题描述】:

当我使用 Try it out 链接 http://docs.microsofttranslator.com/text-translate.html 试用 Translation API 时,我收到如下图所示的 400 错误消息

我正在使用从 Azure 门户生成的访问密钥进行认知服务免费试用。

MS Azure Portal Link

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

【问题讨论】:

    标签: microsoft-cognitive microsoft-translator azure-marketplace bing-translator-api


    【解决方案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'
    

    【讨论】:

    • 不,您不能从浏览器执行该调用,因为它是一个 POST 请求。您应该使用 Postman 之类的工具。 getpostman.com
    • 另外,请编辑您的评论并删除您的订阅密钥!
    • maria,问题令牌调用现在有效...它返回了一个很长的密钥...我将密钥添加到以下 URL 的授权标头中:api.microsofttranslator.com/v2/http.svc/… 它给出了错误,状态 0:服务器没有响应..
    • 啊,网址中有错字...必须是/Translate,而不是/Translat...我的错,对不起
    【解决方案2】:

    您可以通过 2 种方式使用 Microsoft Translator API (see the docs):

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-13
      • 2021-09-08
      • 1970-01-01
      相关资源
      最近更新 更多