sample-proxies/outbound-oauth/apiproxy/resources/jsc/translate-results.js
/**
 * Translate the text to the targetLanguage
 */
Translate the text to the targetLanguage
Translate the text to the targetLanguage
function translate(apiAccessToken, targetLanguage, text) {
  var headers = {
      'Authorization': 'Bearer ' + apiAccessToken
    },
    queryObj = {
      'text': text,
      'to': targetLanguage
    };
  var req = new Request(translatorApi.basePath + 'Translate?' + serializeQuery(queryObj), 'GET', headers);
  var exchange = httpClient.send(req);
  exchange.waitForComplete();
  if (exchange.isSuccess()) {
    var responseObj = exchange.getResponse().content.asXML;
    return responseObj.toString();
  } else if (exchange.isError()) {
    throw new Error(exchange.getError());
  }
}
function translate ( apiAccessToken , targetLanguage , text ) { var headers = { 'Authorization' : 'Bearer ' + apiAccessToken } , queryObj = { 'text' : text , 'to' : targetLanguage } ; var req = new Request ( translatorApi . basePath + 'Translate?' + serializeQuery ( queryObj ) , 'GET' , headers ) ; var exchange = httpClient . send ( req ) ; exchange . waitForComplete ( ) ; if ( exchange . isSuccess ( ) ) { var responseObj = exchange . getResponse ( ) . content . asXML ; return responseObj . toString ( ) ; } else if ( exchange . isError ( ) ) { throw new Error ( exchange . getError ( ) ) ; } }
Translate the text to the targetLanguage
Translate the text to the targetLanguage
// Wait for the asynchronous GET request to finish