我使用 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
});
也许是错误的请求参数?
此处或此处的完整代码:
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);
});
};
});
<!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>