Reputation: 65
I am working on my licence thesis and I have encountered a problem today while trying to run my program. I use microsoft-translator-api to translate some words from Romanian to English, and until now I've had no problem with the translation, everything worked fine, but starting two days ago I have noticed that I'm getting this exception:
java.lang.Exception: [microsoft-translator-api] Error retrieving translation : Server returned HTTP response code: 400 for URL: https://datamarket.accesscontrol.windows.net/v2/OAuth2-13
at com.memetix.mst.MicrosoftTranslatorAPI.retrieveString(MicrosoftTranslatorAPI.java:202)
at com.memetix.mst.translate.Translate.execute(Translate.java:61)
at com.utcn.translator.Translator.translate(Translator.java:16)
at com.utcn.sentenceXmlParser.main.main(main.java:19)
My Translator class looks like this:
package com.utcn.translator;
import com.memetix.mst.detect.Detect;
import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;
public abstract class Translator {
public static String translate(String line) {
Translate.setClientId(/*my client id*/);
Translate.setClientSecret(/*my client secret*/);
String translatedText = null;
try {
translatedText = Translate.execute(line, Language.ROMANIAN,
Language.ENGLISH);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return translatedText;
}
}
Does anybody know how I can solve this issue?
Best regards, Roxana
Upvotes: 2
Views: 2195
Reputation: 65
I found the answer!
First of all I was making to much calls to the microsoft api. After I reduced that I could clearly see the problem. I was getting another exception becouse of a " that was in my text. It seems that microsoft translator api can't process that and it returns a ClassCastException!
Thank you all for your answers!
Upvotes: 1
Reputation: 4300
Most probably the problem is with your credentials. (ClientId
and ClientSecret
).
You can try setting credentials like below (Taken from this thread).
Translate.setClientId("client id you type in the web site");
Translate.setClientSecret("secret you type in the web site in Base 64 format");
Upvotes: 0