[英]WooCommerce Rest API error when use POST and GET
in there i try to use api customers
from woocommerce, when i try to use it i always get response : url : http://example.com/wp-json/wc/v1/customers
在那里我尝试使用来自 woocommerce 的 api
customers
,当我尝试使用它时,我总是得到响应:url: http://example.com/wp-json/wc/v1/customers
: http://example.com/wp-json/wc/v1/customers
{
"code": "woocommerce_rest_cannot_view",
"message": "Sorry, you cannot list resources.",
"data": {
"status": 401
}
}
{
"code": "woocommerce_rest_authentication_error",
"message": "Invalid Signature - provided signature does not match.",
"data": {
"status": 401
}
}
and sometime :有时:
and for create :和创建:
{
"code": "woocommerce_rest_cannot_create",
"message": "Sorry, you are not allowed to create resources.",
"data": {
"status": 401
}
}
what should i do ?我该怎么办?
i already add the key :我已经添加了密钥:
or i only can have 1 key ?还是我只能有 1 把钥匙? :
:
or i need to update one of the script ?或者我需要更新其中一个脚本?
hope, someone can help me to resolve my problem希望有人能帮我解决我的问题
I have encountered this exact issue, however I have good and bad news from my experience, sometimes the API would shut me out when I had made literally no changes, sometimes rebooting the NGINX server would fix this.我遇到了这个确切的问题,但是从我的经验中我有好消息和坏消息,有时当我几乎没有进行任何更改时,API 会将我拒之门外,有时重新启动 NGINX 服务器会解决此问题。
At the moment my connection with postman and OAuth 1.0 yields the following;目前,我与邮递员和 OAuth 1.0 的联系产生以下结果;
{
"code": "woocommerce_rest_cannot_view",
"message": "Sorry, you cannot list resources.",
"data": {
"status": 401
}
}
With that our of the way:有了我们的方式:
As I said above, I never managed to keep mine stable, and it would drop out without changing a single thing.正如我上面所说,我从来没有设法保持我的稳定,它会在不改变任何事情的情况下退出。
How I solved this was by using 'Basic Auth', Username your_ck
, password your_cs
.我解决这个问题的方法是使用“基本
your_ck
验证”,用户名your_ck
,密码your_cs
。 I believe that you need to be using SSL to use Basic Auth but setting up SSL isn't a big deal so it was definitely worth it.我相信您需要使用 SSL 才能使用基本身份验证,但设置 SSL 并不是什么大问题,因此绝对值得。
If you do find out why OAuth 1.0 is failing i'd love to hear.如果您确实发现了 OAuth 1.0 失败的原因,我很想听听。
EDIT: There are many examples of people with this issue example with image may help you.编辑:有很多人有这个问题的例子,图像可能对你有帮助。 But it seems most people settle for Basic Auth.
但似乎大多数人都接受基本身份验证。
Make sure you have given Read/Write Access to the user and also check your .htaccess file in the root directory.确保您已授予用户读/写访问权限,并检查根目录中的 .htaccess 文件。 Try using this code in .htaccess file
尝试在 .htaccess 文件中使用此代码
# BEGIN WordPress
# The directives (lines) between `BEGIN WordPress` and `END WordPress` are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I also faced same issue, i tried in Postman, PHP, NodeJs everthing, almost spend 2 days but no output, finally started getting response after putting a slash at the end of the URL,我也遇到了同样的问题,我在 Postman、PHP、NodeJs 中尝试过,几乎花了 2 天但没有输出,最后在 URL 末尾加上斜杠后开始得到响应,
I mean,我的意思是,
Initially i was using https://example.com/wp-json/wc/v3/products?consumer_key=ck_XXXX&consumer_secret=cs_XXXX but change it to like this https://example.com/wp-json/wc/v3/products/?consumer_key=ck_XXXX&consumer_secret=cs_XXXX (Just put a slash before question mark in the start of query string).最初我使用https://example.com/wp-json/wc/v3/products?consumer_key=ck_XXXX&consumer_secret=cs_XXXX但将其更改为这样https://example.com/wp-json/wc/v3/products /?consumer_key=ck_XXXX&consumer_secret=cs_XXXX (只需在查询字符串开头的问号前加一个斜线)。
In Postman even without set any Authorization settings(Type = No Auth), i started getting responses.在 Postman 中,即使没有设置任何授权设置(Type = No Auth),我也开始收到回复。
It may be somehow related to my .htaccess, but i feel it would good if i post this solution also here.它可能与我的 .htaccess 有某种关系,但我觉得如果我也在这里发布这个解决方案会很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.