API密钥无效Yandex Translate

时间:2016-11-25 20:50:43

标签: javascript angularjs yandex

我使用Yandex-transleyt,并根据要求收到答案" API密钥无效。"它刚收到钥匙。理事会对查询的格式,这个主题没有帮助(Yandex API Translator error - 401 API key is invalid)。 请求格式作为指南:https://tech.yandex.com/translate/doc/dg/reference/translate-docpage/

我的要求:

var url = "https://translate.yandex.net/api/v1.5/tr.json/translate?";
var keyAPI = "trnsl.1.1.20161125T152027Z.65e73e18a60f3051.7764a7a11754995544ad557501df9e14abbfb6e0";

var params = "key=" + keyAPI + "&text=" + textApi + "&lang=" + langApi;
var vm = this;

$http({
    url: url,
    method: 'POST',
    params: params
});

可能是错误的请求参数?

完整代码here或此处:



	var app = angular.module('jsbin', []);

app.controller('DemoCtrl', function($scope, $http) {

	$scope.SendData = function() {
		// тут данные
		var textApi = 'Hello';
		var langApi = 'en-ru';
		var url = "https://translate.yandex.net/api/v1.5/tr.json/translate?";
		var keyAPI = "trnsl.1.1.20161125T152027Z.65e73e18a60f3051.7764a7a11754995544ad557501df9e14abbfb6e0";

		var params = "key=" + keyAPI + "&text=" + textApi + "&lang=" + langApi;
		var vm = this;

		$http({
				url: url,
				method: 'POST',
				params: params
			})
			.success(function(data, headers, status, config) {
				$scope.PostDataResponse = data;
				vm.data = data;
				console.log(data);
			})
			.error(function(data, headers, status, config) {
				$scope.ResponseDetails = "Data: " + data +
					"<hr />status: " + status +
					"<hr />config: " + config;
				console.log("error1");
				console.log(data);
				console.log(status);
				console.log(config);
			});
	};
});
&#13;
<!DOCTYPE html>
<html>
<head>
   <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
  <meta charset="utf-8">
  <title>Angular JS</title>
   </head>
<body ng-app="jsbin">
  <div ng-controller="DemoCtrl as vm">
    
          <button ng-click="SendData()">Send</button>
    <br>
      Data:  {{PostDataResponse}}<br>
    {{vm.data}}
    {{vm.PostDataResponse}}
   Data:  {{scope.PostDataResponse}}
    {{vm.data}}
  </div>
  </body>
  </html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

现在可以了!谢谢大家。

var app = angular.module('jsbin', []);

app.controller('DemoCtrl',function($scope, $http){
    
    $scope.SendData = function () {
          // тут данные
      var textApi='Hello';
      var langApi='en-ru';
       var url = "https://translate.yandex.net/api/v1.5/tr.json/translate?";
    var  keyAPI ="trnsl.1.1.20161125T152027Z.65e73e18a60f3051.7764a7a11754995544ad557501df9e14abbfb6e0";
  
       params ='key='+keyAPI+'&text='+textApi+'&lang='+langApi;
    var vm = this;
       $scope.method = 'POST';
    $scope.url = 'https://translate.yandex.net/api/v1.5/tr.json/translate?';  
      
     $http({
   url: url,
   method:"POST",
   params:{key:keyAPI,text:textApi,lang:langApi},
})
.success(function(data,headers,status,config){
  $scope.PostDataResponse = data;
  vm.data = data;
  console.log(data);
 })
.error(function(data,headers,status,config){
 $scope.ResponseDetails = "Data: " + data +
                "<hr />status: " + status +
                     "<hr />config: " + config;
       console.log("error1");
       console.log(data);
        console.log(status);
       console.log(config)
     }
)
}
}
);
<!DOCTYPE html>
<html>
<head>
   <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
  <meta charset="utf-8">
  <title>Angular JS</title>
   </head>
<body ng-app="jsbin">
  <div ng-controller="DemoCtrl as vm">
    
          <button ng-click="SendData()">Send</button>
    <br>
      Data:  {{PostDataResponse}}<br>
    {{vm.data}}
    {{vm.PostDataResponse}}
   Data:  {{scope.PostDataResponse}}
    {{vm.data}}
  </div>
  </body>
  </html>