在那里我尝试使用来自 woocommerce 的 api 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
}
}
有时:
和创建:
{
"code": "woocommerce_rest_cannot_create",
"message": "Sorry, you are not allowed to create resources.",
"data": {
"status": 401
}
}
我该怎么办?
我已经添加了 key :
或者我需要更新其中一个脚本?
希望有人能帮我解决问题
最佳答案
我遇到过这个确切的问题,但是根据我的经验,我有好消息也有坏消息,有时当我几乎没有做任何更改时 API 会把我拒之门外,有时重新启动 NGINX 服务器会解决这个问题。
目前我与 postman 和 OAuth 1.0 的联系产生了以下结果;
{
"code": "woocommerce_rest_cannot_view",
"message": "Sorry, you cannot list resources.",
"data": {
"status": 401
}
}
我们的方式:
- 确保在 postman 中将“类型”设置为 OAuth 1.0。
- 确保您的 URL 正确(http 或 https)。
正如我上面所说,我从来没有设法保持我的稳定,它会在不改变任何东西的情况下退出。
我是如何解决这个问题的,方法是使用“基本身份验证”、用户名 your_ck
、密码 your_cs
。我相信您需要使用 SSL 才能使用 Basic Auth,但设置 SSL 不是什么大问题,因此绝对值得。
如果您确实知道 OAuth 1.0 失败的原因,我很乐意听到。
编辑:有很多人遇到这个问题的例子 example with image可能会帮助你。但似乎大多数人都满足于基本身份验证。
关于javascript - 使用 POST 和 GET 时 WooCommerce Rest API 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40280602/