【问题标题】:WooCommerce REST API "woocommerce_rest_cannot_view "WooCommerce REST API“woocommerce_rest_cannot_view”
【发布时间】:2019-02-05 16:53:17
【问题描述】:

当我粘贴此链接时

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}}

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

【问题讨论】:

    标签: rest api woocommerce wordpress-rest-api woocommerce-rest-api


    【解决方案1】:

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

    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

    【讨论】:

      【解决方案2】:

      通过将下面这一行添加到 .htaccess 文件的末尾来解决问题

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

      SetEnv HTTPS 开启

      并确保使用 OAuth 1.0 进行授权

      【讨论】:

        【解决方案3】:

        你的连接必须是 https 并将此行添加到您的 woocommerce 初始化中:

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

        每个帖子请求都需要 ssl

        从此链接复制 Ionic 3 WP-REST API Post request 401 (unauthorized) error & WooCommerce REST API "woocommerce_rest_cannot_view "

        【讨论】:

        • queryStringAuth: true 是我的解决方案
        • 对不起,我不知道 wordpress。我找不到 woocommerce init。有什么线索吗?
        【解决方案4】:

        401 是未经授权的错误

        如果 key 和 secret 正确,则可能是 SSL

        其他人报告了类似的问题

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

        【讨论】:

          猜你喜欢
          • 2017-06-30
          • 1970-01-01
          • 2018-08-28
          • 1970-01-01
          • 1970-01-01
          • 2018-03-31
          • 1970-01-01
          • 2021-06-02
          • 2019-03-31
          相关资源
          最近更新 更多