Woocommerce REST API 401

我只是一个虾纸丫 提交于 2019-12-04 05:21:20

问题


similar question has been asked before however I am not sure if the proposed solutions can be applied in my case. I have generated consumerKey and consumerSecret as per the woocommerce api documentation. I have confirmed that I can get the results using these keys by calling the below url in the webbrowser:

https://mywebsite.com/wp-json/wc/v2/products?consumer_key=ck_blahblah&consumer_secret=cs_blahblah

However, when I execute the same api call in the postman, using GET and correctly replacing user-> consumerKey and pass -> consumerSecret I always get 401 : woocommerce_rest_cannot_view. I have tried both http and https with the same error. Any ideas?


回答1:


Use this plugin https://github.com/WP-API/Basic-Auth and when you call the API use the Basic Authentication using the username and password.




回答2:


Woo Commerce uses a diferent authentication method for HTTP and HTTPS.

So, if "HTTPS" = 1 is not being passed by Apache/Nginx to you code it will enforce the HTTP method.

Do a double check if this "HTTPS" is passed to your PHP:

  1. Open the file: ./wp-includes/load.php
  2. Search for "is_ssl"
  3. Insert a "echo 'test_beg'; echo $_SERVER['HTTPS']; echo 'test_end';
  4. Do a request on the API
  5. If it return test_beg and test_end without "on" or "1" in the middle, the HTTPS is not being passedList item

It can happen when using a reverse proxy, so, you could need to insert "SetEnvIf HTTPS on HTTPS=on" on your httpd.conf (if using Apache).

I hope it helps :)

(remember to delete these 'echo' on load.php)



来源:https://stackoverflow.com/questions/49374319/woocommerce-rest-api-401

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!