MS Translator returns empty response when used wit

2020-02-15 06:39发布

I've already posted this in the MSDN forum and have no response. I'm trying to port an application that uses MS Translator that has been using the old authentication token mechanism (client ID, client secret) to use MS Azure. To that end, I set up an Azure account, added the MS Translator API through the cognitive services, and generated keys as per the instructions found here: https://translatorbusiness.uservoice.com/knowledgebase/articles/1078534-microsoft-tran I am able to call the Azure authentication page as documented here: http://docs.microsofttranslator.com/oauth-token.html However, when I use the token that I get from that method (both from my own request and from the swagger API docs that allows you to try the call), and call any of the methods in the API, I get a response code of 0 and a response error header saying 'no response from server'.

Part of my confusion is I'm not absolutely sure what key/subscription ID I should be using. When I subscribed, I got a subscription ID which doesn't work when calling the issueToken method. I also have two keys generated (a key1, and a key2) with the option to regenerate them. Both will give me back an authToken, but when I call any method in the API, I get the same empty response.

For example, when I called the GetLanguagesForTranslate method using their swagger API doc (i.e. the try it button), my request has the following headers:

Host: api.microsofttranslator.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Access-Control-Request-Method: GET
Access-Control-Request-Headers: authorization
origin: htee-tee-pee(slash-slash)docs.microsofttranslator.com

My response is empty.

Can anyone give me a clue to what is going on? Could it be because for whatever reason my subscription is just a trial? MS won't allow me to log a support ticket unless I buy a subscription. I don't want to do that because I'm working for a client and once this work is done, I won't be using the subscription anymore. Thanks in advance

标签: rest azure
1条回答
不美不萌又怎样
2楼-- · 2020-02-15 06:53

It sounds like you were able to get the access token with the key got from Azure Portal via http://docs.microsofttranslator.com/oauth-token.html.

Per my experience, I think the no response issue seems to be caused by setting incorrectly for parameters appid & Authorization. For example, setting the appid value with any string (such as your registed Azure service name) and setting the Authorization value with Bearer <access-token>.

However, as the description for appid below.

REQUIRED. If the Authorization header is used, leave the appid field empty else specify a string containing "Bearer" + " " + access token.

It means that you just need to set the appid value with Bearer <access-token> and put the Authorization value empty, as see the figure below.

enter image description here

Click Try it out!, then got as below.

enter image description here

查看更多
登录 后发表回答