WooCommerce REST API Authentication fails when log

2019-07-31 15:49发布

问题:

WooCommerce REST API Authentication is failing when I am logged into Wordpress in the same browser.

Log out - everything works

Log in - and get this error:

{"code":"woocommerce_rest_cannot_view","message":"Sorry, you cannot view this resource.","data":{"status":401}}

Same goes for Ajax:

jQuery.ajax({
    url:'https://example.com/wp-json/wc/v1/products/30552?consumer_key=ck_xxx&consumer_secret=cs_xxx',
    success:function(d){window.d = d;}
}); 

and when trying to access the same URL directly in the browser.

What could be causing this situtation?

I can't think of any useful reason for it.

回答1:

This has been fixed for WooCommerce 2.7.

https://github.com/woocommerce/woocommerce/commit/b1b536b5d2aa19a2967466acc90a6547955b8595