微软Azure翻译AJAX API不工作 [英] Microsoft Azure Translator AJAX API not working

查看:174
本文介绍了微软Azure翻译AJAX API不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从MS必应翻译的当前版本转换为新的Azure之一。

I am trying to convert from the current version of MS Bing Translator to the new Azure one.

我创建了一个访问令牌作为新的文件中,虽然描述的由微软提供的下面的例子(为天青)正常工作:

I created an access token as described in the new documentation and although the following example (for Azure) supplied by Microsoft works correctly:

function translate() {

  var from = "en", to = "es", text = "hello world";
  var s = document.createElement("script");
  s.src = "http://api.microsofttranslator.com/V2/Ajax.svc/Translate" +
            "?appId=" + settings.appID +
            "&from=" + encodeURIComponent(from) +
            "&to=" + encodeURIComponent(to) +
            "&text=" + encodeURIComponent(text) +
            "&oncomplete=mycallback";
  document.body.appendChild(s);
}

function mycallback(response) {
  alert(response); 
}

我想上面的code转换为jQuery的电话。

I would like to convert the above code to a jQuery call.

我修改从工作的previous版本类似jQuery的AJAX调用,但 parseerror-jQuery17206897480448242277_1343343577741不叫发出:

I modified a similar jQuery ajax call from the previous version which worked, but a parseerror-jQuery17206897480448242277_1343343577741 was not called is issued:

  function jqueryTranslate() {
    var p = {};
    p.appid = settings.appID;
    p.to = "es";
    p.from = "en";
    p.text = "Goodbye Cruel World";
    p.contentType = 'text/html';
    $.ajax({
      url: 'http://api.microsofttranslator.com/V2/Ajax.svc/Translate',
      data: p,
      dataType: 'jsonp',
      jsonp: 'oncomplete',
      complete: function (request, status) {
      },
      success: function (result, status) {
        alert(result);
      },
      error: function (a, b, c) {
        alert(b + '-' + c);
      }
    });
  }

我非常AP preciate和什么错误,所以TIA你的时间的理解。

I would very much appreciate and understanding of what is going wrong, so TIA for your time.

推荐答案

另一个问题是,必应的AppID机制进行身份验证翻译已经去precated。

The other issue is that the Bing AppID mechanism for authenticating against translator has been deprecated.

微软有一篇博客文章,详细说明获取访问翻译在Windows Azure市场这里的过程:

Microsoft have a blog post detailing the process for getting access to Translator in the Windows Azure Marketplace here:

http://blogs.msdn.com/b/translation/p/ gettingstarted1.aspx

有在ASP.NET的例子在这里:
http://blogs.msdn.com/b/translation/p/gettingstarted2.aspx

There's an example in ASP.NET here: http://blogs.msdn.com/b/translation/p/gettingstarted2.aspx

的建议是(至少)把你的code让你的令牌服务器端在ASP.NET,PHP,节点或类似的东西,让你的客户ID和客户端密钥不被暴露。

The recommendation is (at least) to put your code for getting your token server side in ASP.NET,PHP,Node or something similar so that you Client ID and Client Secret aren't exposed.

一旦你得到的访问令牌,它需要被写入调用服务的HTTP标头。 ASP.NET示例表明,它应该是比较容易适应JQuery的。

Once you've gotten the access token, it needs to be written into the HTTP headers of the call to the service. The ASP.NET sample shows that, and it should be relatively easy to adapt to JQuery.

这篇关于微软Azure翻译AJAX API不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆