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

查看:82
本文介绍了“无法列出资源"来自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:

{代码":"woocommerce_rest_cannot_view",消息":对不起,您不能列出资源.,"数据:{"状态: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?

推荐答案

对于新" v2 API(不是旧版v2" API):

For the "new" v2 API (not the "legacy v2" API):

  • 对于安全连接(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

还请注意,通常您会将CK和CS作为标头字段传递,但是根据服务器的配置方式,您可能会发现它无法正确解析标头字段,因此,如果包括URL中的CK和CS作为参数:

Also note that 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://网站.tld/wp-json/wc/v1/products?consumer_key = [key]& consumer_secret = [秘密]

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

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