1

当我粘贴此链接时

http://localhost/wordpress/wp-json/wc/v2/products?consumer_key=ck_ *******************&consumer_secret=cs_******* *************

它向我显示此错误消息

{"code":"woocommerce_rest_cannot_view","message":"D\u00e9sol\u00e9, vous ne pouvez pas lister les ressources.","data":{"status":401}}

顺便说一句,消费者的密钥和秘密是正确的

4

5 回答 5

1

您的连接必须是 https 并将此行添加到您的 woocommerce init :

{
....
      verifySsl: false,
      queryStringAuth: true
}

每个帖子请求都需要 ssl

从此链接复制 Ionic 3 WP-REST API 发布请求 401(未经授权)错误WooCommerce REST API “woocommerce_rest_cannot_view”

于 2018-09-03T21:24:17.180 回答
0

401 是未经授权的错误

如果 key 和 secret 正确,则可能与 SSL 相关

其他人报告了类似的问题

https://github.com/woocommerce/woocommerce/issues/19649

于 2018-08-30T18:15:10.003 回答
0

这里有两种可能的解决方案:

  1. 在 WordPress 安装的 index.php 页面中添加以下变量(在我的本地主机上为我工作,无需重新启动服务器):

$_SERVER['HTTPS'] = 'on'; //------> Add this line under the line that says: define( 'WP_USE_THEMES', true );

  1. 使用 Apache 时在 .htaccess 文件中设置环境变量:

SetEnv HTTPS on

于 2021-11-21T12:55:01.250 回答
0

在像这样创建 RestAPI 的末尾添加 false ...

RestAPI rest = new RestAPI(URL, ConsumerKey, ConsumerSecret, false);

它应该由“authorizedHeader”

来自https://github.com/XiaoFaye/WooCommerce.NET/issues/211的回答

于 2022-02-08T07:26:25.207 回答
-1

通过将此行添加到 .htaccess 文件的末尾来解决问题

只需将此行添加到 .htaccess ,这对我有用

SetEnv HTTPS 开启

并确保使用OAuth 1.0进行授权

在此处输入图像描述

于 2021-04-10T13:59:37.697 回答