API 密钥无效 Yandex Translate
Posted
技术标签:
【中文标题】API 密钥无效 Yandex Translate【英文标题】:API key is invalid Yandex Translate 【发布时间】:2016-11-25 20:50:43 【问题描述】:我使用 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);
);
;
);
<!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>
【问题讨论】:
【参考方案1】:现在可以了!谢谢大家。
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>
【讨论】:
以上是关于API 密钥无效 Yandex Translate的主要内容,如果未能解决你的问题,请参考以下文章
通过 API 创建短链接并获取“API 密钥无效。请传递有效的 API 密钥”
MailChimp 错误状态:401 标题:“API 密钥无效”