Angularjs 使用Angular的电子商务中的身份验证错误
我正在Cordova平台上的Angular/Ionic项目中实现Woo Commerce Rest API。当我发出$http请求以获取产品列表或任何其他数据时,我收到了错误消息。这是我的服务代码:Angularjs 使用Angular的电子商务中的身份验证错误,angularjs,wordpress,cordova,ionic-framework,woocommerce,Angularjs,Wordpress,Cordova,Ionic Framework,Woocommerce,我正在Cordova平台上的Angular/Ionic项目中实现Woo Commerce Rest API。当我发出$http请求以获取产品列表或任何其他数据时,我收到了错误消息。这是我的服务代码: angular.module('services.serverRepo', []) .service("serverRepo", ['$q','$http','errorHandler','$ionicLoading',function($q,$http,errorHandler,$ionicLo
angular.module('services.serverRepo', [])
.service("serverRepo",
['$q','$http','errorHandler','$ionicLoading',function($q,$http,errorHandler,$ionicLoading){
var baseUrl="www.abc.com/wc-api/";
var self=this;
this.products=function(){
var deff=$q.defer();
$http({
method:"GET",
url:baseUrl+"v3/products",
headers: {
"Content-Type":"application/JSON",
"oauth_consumer_key":"gjdfjkbgbdhh645h6bh456b45hbhbgdfhgbdfhgbdfhgbhgbdhfghhfhf",
"consumer_secret":"cs_97d74bbf5e9052ee053a05cbb1a53eec19c0847c"
}
}).then(function(objS){
alert('Success :- '+JSON.stringify(objS));
},function(objE){
alert('error:- '+objE);
errorHandler.serverErrorhandler(objE);
deff.reject("server Error");
});
return deff.promise;
};
}])
.service('errorHandler',['$q',function($q){
this.serverErrorhandler=function(error){
alert("ERROR ::"+JSON.stringify(error));
console.log("ERROR ::"+JSON.stringify(error));
};
}
])
在我的controller.js文件中,代码是:
$scope.rentaldeptt = function(){
//$ionicHistory.clearCache();
serverRepo.products().then(function(objS){
},function(err){
});
}
我正在通过单击按钮调用$scope.rentaldeptt
。作为回应,我收到了错误消息
{“data”:{“errors”:[{“code”:“woocommerce\u api\u authentication\u error”,“message”:“oauth\u timestamp参数丢失”}],“status”:404,“config”:{“method”:“GET”,“transformRequest”:[null],“transformResponse”:[null],“url”:“www.abc.com/v3/products”,“headers”:{“Accept”:“application/json,text/plain,/”,“params”:{“oauth\u consumer key”:“GJDFJKBGBDHH645H6BH456B45HBHBGDFHGDFHGBDFHGBDHGHHF”,“消费者机密”:“cs_97d74bbf5e9052ee053a05cbb1a53eec19c0847c”},“状态文本”:“未找到”}
知道我做错了什么吗?请尝试以下步骤来解决问题 在这里,我用angularjs创建了服务,用oauth处理WooCommerceAPI的调用
angular.module('myapp.restservices', [])
.service("serverRepo",['$q','$http','errorHandler','$ionicLoading',function($q,$http,errorHandler,$ionicLoading){
var self=this;
//Request Url and method
var request = {
url: 'http://www.example.com/wc-api/v3/products',
method: 'GET'
};
//OAuth Protocol authentication parameters
var oauth = new OAuth({
consumer: {
//Consumer Public Key
public: 'ck_50xxxx',
//Consumer Secrete Key
secret: 'cs_b4xxxx'
},
//oauth1.0a protocol signature method
signature_method: 'HMAC-SHA1'
});
//Service Function to get products
this.products=function(){
$ionicLoading.show({
template: '<ion-spinner class="light"></ion-spinner>'
});
//OAuth Parameters to call woocommerce api
var oauth_data = {
oauth_consumer_key: oauth.consumer.public,
oauth_nonce: oauth.getNonce(),
oauth_signature_method: oauth.signature_method,
oauth_timestamp: oauth.getTimeStamp()
};
//Oauth signature
oauth_data.oauth_signature = oauthSignature.generate(request.method,request.url,oauth_data,oauth.consumer.secret );
console.log("Params : "+ JSON.stringify(oauth_data));
var deff=$q.defer();
$http({
method:"GET",
url:request.url,
headers: {
"Content-Type":"application/JSON",
},
params: oauth_data
}).then(function(objS){
$ionicLoading.hide();
alert('Success :- '+JSON.stringify(objS));
},function(objE){
$ionicLoading.hide();
alert('error:- '+JSON.stringify(objE));
errorHandler.serverErrorhandler(objE);
deff.reject("server Error");
});
return deff.promise;
};
}])
.service('errorHandler',['$q',function($q){
this.serverErrorhandler=function(error){
alert("ERROR ::"+JSON.stringify(error));
console.log("ERROR ::"+JSON.stringify(error));
};
}
])
希望这将对您有所帮助!请尝试以下步骤来解决isue 在这里,我用angularjs创建了服务,用oauth处理WooCommerceAPI的调用
angular.module('myapp.restservices', [])
.service("serverRepo",['$q','$http','errorHandler','$ionicLoading',function($q,$http,errorHandler,$ionicLoading){
var self=this;
//Request Url and method
var request = {
url: 'http://www.example.com/wc-api/v3/products',
method: 'GET'
};
//OAuth Protocol authentication parameters
var oauth = new OAuth({
consumer: {
//Consumer Public Key
public: 'ck_50xxxx',
//Consumer Secrete Key
secret: 'cs_b4xxxx'
},
//oauth1.0a protocol signature method
signature_method: 'HMAC-SHA1'
});
//Service Function to get products
this.products=function(){
$ionicLoading.show({
template: '<ion-spinner class="light"></ion-spinner>'
});
//OAuth Parameters to call woocommerce api
var oauth_data = {
oauth_consumer_key: oauth.consumer.public,
oauth_nonce: oauth.getNonce(),
oauth_signature_method: oauth.signature_method,
oauth_timestamp: oauth.getTimeStamp()
};
//Oauth signature
oauth_data.oauth_signature = oauthSignature.generate(request.method,request.url,oauth_data,oauth.consumer.secret );
console.log("Params : "+ JSON.stringify(oauth_data));
var deff=$q.defer();
$http({
method:"GET",
url:request.url,
headers: {
"Content-Type":"application/JSON",
},
params: oauth_data
}).then(function(objS){
$ionicLoading.hide();
alert('Success :- '+JSON.stringify(objS));
},function(objE){
$ionicLoading.hide();
alert('error:- '+JSON.stringify(objE));
errorHandler.serverErrorhandler(objE);
deff.reject("server Error");
});
return deff.promise;
};
}])
.service('errorHandler',['$q',function($q){
this.serverErrorhandler=function(error){
alert("ERROR ::"+JSON.stringify(error));
console.log("ERROR ::"+JSON.stringify(error));
};
}
])
希望这能对你有所帮助!你有解决方案吗?没有,我还是没有得到这个问题的答案谢谢你的重播,我有解决方案如果你在这里发帖就太好了。请检查答案是否正确你有解决方案吗?没有,我还是没有得到这个问题的答案谢谢你的重播,我有解决方案。这将是grea如果你在这里发帖,请检查答案是否正确