Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
657 views
in Technique[技术] by (71.8m points)

rest - MS Translator returns empty response when used with Azure token

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...