Search code examples
phpapiazurecurlmicrosoft-translator

Translation using Microsoft Translator API Timeout


I am willing to translate a particular text in 3 different languages using using Microsoft Translator API. I configured it and, apparently, the link I get which should drive me to translation breaks:

https://api.datamarket.azure.com/Data.ashx/Bing/MicrosoftTranslator/v1/Translate?Text=%27Osteopathy%27&From=%27en%27&To=%27nl%27&$format=Raw&$top=100

I tried it also in my terminal with curl, with authorization, but it seems that no response is sent:

$ curl -H 'Authorization: Basic ***my authorization_key encoded in base64***' 'https://api.datamarket.azure.com/Data.ashx/Bing                                                                                                       /MicrosoftTranslator/v1/Translate?Text=%27Osteopathy+for+Babies%27&From=%27en%27&To=%27nl%27&$format=Raw&$top=100'

The response from Microsoft Translator doesn't come. It simply times out.

The same piece of code worked few weeks ago.

What could be the cause? How to fix this?


Solution

  • I tried the same request as you and I do get a response back from the server but it's a 403 forbidden. I can't speculate on why the code no longer works but if you also get back a 403 it might be worth refreshing the key, it might have expired somehow. Otherwise the behaviour of the API has changed in a breaking way, it's hard to say without any official documentation.

    However, you could try the Microsoft Cognitive Services API, it took be about 5 mins to setup. You will need to use OAuth bearer tokens instead of basic auth, but this is more secure anyway.

    Setup docs https://www.microsoft.com/en-us/translator/getstarted.aspx

    Getting a token http://docs.microsofttranslator.com/oauth-token.html

    And some code samples on github under MicrosoftTranslator/HTTP-Code-Samples