Woocommerce API 身份验证错误 [英] Woocommerce API Authentication Error
本文介绍了Woocommerce API 身份验证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 Woocommerce API 作为 AngularJS 和 Ionic 应用程序进行身份验证.这是我的代码.
I am trying to authenticate as an AngularJS and Ionic App with Woocommerce API. Here is my code.
var ck = 'ck_6fffb5cbc00eqe00a7c3062cd85dae2ee64f919e';
var cs = 'cs_c2fd467cqq8857a08941c15bc708e3c16dc1f026';
var url = 'http://www.mysitecom/wc-api/v3';
var httpMethod = 'GET',
parameters = {
oauth_consumer_key : ck,
oauth_token : '370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb',
oauth_nonce : 'kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg',
oauth_timestamp : new Date().getTime(),
oauth_signature_method : 'HMAC-SHA1',
oauth_version : '1.0'//,
//file : 'vacation.jpg',
//size : 'original'
},
consumerSecret = cs,
tokenSecret = 'pfkkdhi9sl3r4s00';
var signature = oauthSignature.generate( httpMethod, url, parameters, cs, tokenSecret, { encodeSignature: true } );
console.log(signature);
$http.get(url+'/products?oauth_consumer_key='+ck+'&oauth_nonce='+parameters.oauth_nonce+'&oauth_signature='+signature+'&oauth_signature_method=HMAC-SHA1&oauth_timestamp='+parameters.oauth_timestamp+'&oauth_token='+parameters.oauth_token+'oauth_version=1.0').then(function(data){
console.log(data);
}, function(error){
console.log(error);
});
我总是收到错误.
PS:我正在使用 this javascript 库来生成签名.
PS: I am using this javascript library to generate the signature.
推荐答案
我做到了.第一天我差点就做了,不知怎么的错过了.
I did it. I was so close to doing it on the first day, somehow missed it.
var ck = 'ck_abcdefghijklmnopqrstuvwxyz';
var cs = 'cs_zyxwvutsrqponmlkjihgfedcba';
var url = 'http://samplesite.com/wc-api/v3/products';
var oauth = OAuth({
consumer: {
public: ck,
secret: cs
},
signature_method: 'HMAC-SHA1'
});
var request_data = {
method: 'get',
}
var params = oauth.authorize(request_data);
console.log(params);
$http.get(url+'/?oauth_signature='+ params.oauth_signature+ '&oauth_consumer_key='+ck+'&oauth_nonce='+params.oauth_nonce+'&oauth_signature_method=HMAC-SHA1&oauth_timestamp='+params.oauth_timestamp+'&oauth_token='+params.oauth_token+'&oauth_version=1.0')
.then(function(data){
console.log(data);
$scope.products = data.data.products;
}, function(error){
console.log(error);
});
不要忘记在此处实现 OAuth 库.
Don't forget to implement the OAuth library here.
这篇关于Woocommerce API 身份验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文