2016-11-25 8 views
0

私はYandex-transleytを使用しており、リクエストに応じて「APIキーが無効です」というメッセージが表示されます。ちょうど鍵を受け取りました。評議会のクエリのフォーマットでは、このトピックは助けていません(Yandex API Translator error - 401 API key is invalid)。ガイドとして リクエスト形式:https://tech.yandex.com/translate/doc/dg/reference/translate-docpage/APIキーが無効ですYandex Translate

マイリクエスト:

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かここに:

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

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

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

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

 
\t \t $http({ 
 
\t \t \t \t url: url, 
 
\t \t \t \t method: 'POST', 
 
\t \t \t \t params: params 
 
\t \t \t }) 
 
\t \t \t .success(function(data, headers, status, config) { 
 
\t \t \t \t $scope.PostDataResponse = data; 
 
\t \t \t \t vm.data = data; 
 
\t \t \t \t console.log(data); 
 
\t \t \t }) 
 
\t \t \t .error(function(data, headers, status, config) { 
 
\t \t \t \t $scope.ResponseDetails = "Data: " + data + 
 
\t \t \t \t \t "<hr />status: " + status + 
 
\t \t \t \t \t "<hr />config: " + config; 
 
\t \t \t \t console.log("error1"); 
 
\t \t \t \t console.log(data); 
 
\t \t \t \t console.log(status); 
 
\t \t \t \t console.log(config); 
 
\t \t \t }); 
 
\t }; 
 
});
<!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>

答えて

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>

関連する問題