“无法列出资源"来自 WooCommerce REST API 的错误 [英] "cannot list resources" error from WooCommerce REST API

查看:55
本文介绍了“无法列出资源"来自 WooCommerce REST API 的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 WordPres` 非常陌生,第一次使用 WooCommerce 插件,想在我的 Android 应用程序中使用 WooCommerce REST API.

I am very new to WordPres` and using the WooCommerce plugin for the first time and want to use the WooCommerce REST API in my Android app.

我已启用 REST API 并创建了消费者密钥和消费者机密.

I have enabled the REST API and created a Consumer Key as well as a Consumer secret.

现在,当我在浏览器中使用这个 url http://www.my-domain.com/wp-json/wc/v1/products/ 来检查 API 是否正常工作或不,我收到此错误:

Now, when am using this url http://www.my-domain.com/wp-json/wc/v1/products/ in my browser to check if the API is working or not, I get this error:

{"code":"woocommerce_rest_cannot_view","message":"抱歉,您不能列出资源.","data":{"status":401}}

{"code":"woocommerce_rest_cannot_view","message":"Sorry, you cannot list resources.","data":{"status":401}}

我的服务器上没有安装 SSL.我怎样才能解决这个问题?我需要使用 PHP 客户端库吗?

SSL is not installed on my server. How can I fix this? Do I need to use the PHP Client Library?

推荐答案

身份验证方法

对于较新的 v3 API(不是遗留"API):

For the newer v3 API (not the "legacy" APIs):

  • 对于安全连接 (HTTPS),您需要使用基本身份验证".
  • 对于非安全连接 (HTTP),您需要使用oAuth1 身份验证".

如果您使用错误的身份验证和错误的连接,您将收到 401 响应消息.

If you use the wrong authentication with the wrong connection, you'll get the 401 response message.

这在 WooCommerce API 文档中有介绍:https://woocommerce.github.io/woocommerce-rest-api-docs/#authentication-over-https

This is covered in the WooCommerce API documentation: https://woocommerce.github.io/woocommerce-rest-api-docs/#authentication-over-https

API 登录用户名和密码(还有消费者密钥丢失"错误)

通常您会将 CK 和 CS 作为头字段传入,但是根据服务器的配置方式,您可能会发现它不会正确解析头字段,因此如果包含 CK 和 CS,您可能会成功在 URL 中作为参数:

Normally you would pass the CK and CS in as header fields, but depending on how the server is configured, you may find that it will not parse the header fields correctly, so you may get success if you include the CK and CS in the URL as parameters:

https:///website.tld/wp-json/wc/v1/products?consumer_key=[key]&consumer_secret=[secret]

Apache 授权变量

如果您使用 FCGId,您可能需要在 Apache 中填写授权变量.在您的 .htaccess 或网站部分,添加以下内容:

You may need to fill the authorization variable in Apacheif you use FCGId. In your .htaccess or sites sections, add this :

<IfModule mod_fcgid.c>
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

(https://fuelphp.com/forums/discussion/12825/rest-authentication-does-not-work-under-default-cgi-configurations-solution-within/p1)

这篇关于“无法列出资源"来自 WooCommerce REST API 的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆