Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Extjs Bing Translator EXT JS访问令牌_Extjs_Localization_Token_Microsoft Translator - Fatal编程技术网

Extjs Bing Translator EXT JS访问令牌

Extjs Bing Translator EXT JS访问令牌,extjs,localization,token,microsoft-translator,Extjs,Localization,Token,Microsoft Translator,我正在尝试将Bing翻译程序连接到我的EXT JS。我在尝试获取访问令牌时遇到问题。不管我做了什么,我都收到了400个错误的请求 这是我的代码: var clientId = encodeURI("<my id>"), clientSecret = encodeURI("<my secret>"), scope = encodeURI("http://api.microsofttranslator.com"), grantType = encod

我正在尝试将Bing翻译程序连接到我的EXT JS。我在尝试获取访问令牌时遇到问题。不管我做了什么,我都收到了400个错误的请求

这是我的代码:

 var clientId = encodeURI("<my id>"),
    clientSecret = encodeURI("<my secret>"),
    scope = encodeURI("http://api.microsofttranslator.com"),
    grantType = encodeURI("client_credentials");        
    var params = {client_id     :  clientId,
                  client_secret :  clientSecret,
                  scope         :  scope, 
                  grant_type    :  grantType};
    Ext.Ajax.request({
               url     : "https://datamarket.accesscontrol.windows.net/v2/OAuth2-13/",
               method  : "POST",
               params  : params,
               success : function(response) {
                            alert("Success");
               },
               fail    : function() {
                            alert("Fail");
               }
    }); 
var clientId=encodeURI(“”),
clientSecret=encodeURI(“”),
范围=编码URI(“http://api.microsofttranslator.com"),
grantType=encodeURI(“客户端凭据”);
var params={client_id:clientId,
客户机密:clientSecret,
范围:范围,,
grant_type:grantType};
Ext.Ajax.request({
url:“https://datamarket.accesscontrol.windows.net/v2/OAuth2-13/",
方法:“张贴”,
params:params,
成功:功能(响应){
警惕(“成功”);
},
失败:函数(){
警报(“失败”);
}
}); 

我开始认为这是不可能的。我相信这是一个不允许的请求。也许它在做这个客户端?或者https url在Ajax.request中不起作用。非常感谢您的帮助

不太熟悉Ext.Ajax,但请尝试以下方法:

  • 试着做一个GET而不是POST
  • 将参数放在查询字符串中,即https://?clientid=&等,而不是您现有的参数

  • 正如你所说,这是不可能的。注意,您需要使用JSONP+GET向第三方服务器发出任何请求,但Bing Translator API除外。尽管在代码中指明了POST(使用Chrome Developer工具或类似工具来检查这一点),但浏览器仍在为您的请求使用GET,因为JSONP和POST不兼容(请参阅)

    Bing Translator API的早期版本接受GET请求,但情况不再如此。解决方案:您需要实现自己的服务器端服务来获取访问令牌和翻译,然后将后者返回到浏览器

    顺便说一句,这是一个类似的代码,它使用JQuery来获取访问令牌,但由于相同的原因无法工作:

    $.ajax({
      type: "POST",
      url: "https://datamarket.accesscontrol.windows.net/v2/OAuth2-13",
      data: {client_id:"bbcat",client_secret: "SECRETKEY",
         scope: "http://api.microsofttranslator.com", grant_type: "client_credentials"},
      dataType: "jsonp",
      success: function(data) {
        console.log(data);
      },
      error: function(data) {
        console.error(data);
      }
    });
    

    您不能跨域使用Ext.Ajax,您需要使用JSONP或formpost从第三方域获取数据