Customer Questions:

Provide Sample Java Program to connect Microsoft Azure Text Translation API and get translated text back.

Please, provide the sample java program (e.g. like hello world program) to connect with micro-soft azure text translator and get back my translated text. I have verified in text translator api documentation available in http://docs.microsofttranslator.com/text-translate.html but haven't find any information with respective to Java language.

Early help is appreciated. Thanks in advance.

2 votes
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)

    We’ll send you updates on this idea

    varavara shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    4 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Pete EPete E commented  ·   ·  Flag as inappropriate

        Vara
        Code to get token is under solution to question 'Java code to get Access Token'
        Pete

      • Pete EPete E commented  ·   ·  Flag as inappropriate

        Vara: re-posted reply:
        import java.net.URL;
        import java.net.URLConnection;
        import java.io.InputStreamReader;
        import java.io.BufferedReader;
        URL urlval;
        URLConnection conn;
        InputStreamReader ir;
        BufferedReader rb;
        String urlstr = new String();
        String line = new String();
        String linefull = new String();
        String tokenstr = new String();
        String urlstr = new String();
        // Obtain tokenstr value via "https://api.cognitive.microsoft.com/sts/v1.0/issueToken" plus
        // "Ocp-Apim-Subscription-Key" and one of the two key values got when signing up
        // N.B. If you haven't done this yet see my response to this issue
        urlstr = "https://api.microsofttranslator.com/v2/http.svc/Translate?appid=Bearer%
        urlstr = urlstr + tokenstr;
        // text value contains %20 to represent each space
        urlstr = urlstr + "&text="+ "The%20cat%20sa%20on%20the%20mat";
        urlstr = urlstr + "&from=" + "en" + "&to=" + "fr" // Example English to French
        try {
        urlval = new URL(urlstr);
        conn = urlval.openConnection();
        ir = new InputStreamReader(conn.getInputStream(), "UTF-8");
        rb = new BufferedReader(ir);
        while ((line = rb.readLine()) != null)
        {
        if (line.length() > 0)
        {
        linefull = linefull + line;
        }
        }
        rb.close();
        ir.close();
        System.out.println(linefull);
        //end up with 'linefull' set to the following which you can interpret:
        // "<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Le chat sa sur le tapis</string>"
        //
        }
        catch (Exception e)
        {
        System.out.println(e.getMessage());
        return null;
        }
        Same as before: will add other posts as well

      • Pete EPete E commented  ·   ·  Flag as inappropriate

        Hello vara
        I thought I I had answered this: I don't know where my answer has gone
        Pete

      Feedback and Knowledge Base