WooCommerce api authentication error oauth_consume

2019-07-29 04:42发布

问题:

I try to fetch all product data list in json from WooCommerce API and type address bar http://www.batata.in/wc-api/v3/orders. But it give an error:

{"errors"[{"code":"woocommerce_api_authentication_error","message":"oauth_consumer_key parameter is missing"}]}

I tried all things but issue is not fixed. Rest API is on.

If anybody know any other way to find product list in json format from WooCommerce WordPress plugins, then please tell me.

回答1:

Please note that you need to provide consumer key, nonce, signature with your rest api call. Following is the format which worked for me.

http://SomeURL.com/wc-api/v2/orders?oauth_consumer_key=########&oauth_timestamp=######&oauth_nonce=#############&oauth_signature_method=HMAC-SHA256&oauth_signature=##########################

For generating nonce and signature I recommend you use some wrapper available for your platform. I used php so got a nice library here.

https://github.com/woocommerce/wc-api-php

Important:- Even after following all above steps correct I got the same issue you faced. It kept giving me error "oauth_consumer_key parameter is missing" which actually was misleading. The issue I figured out was the basic http auth. I had http authentication in place so the curl request I used to fire was returning 401 unauthorized. If you are using php you will understand following line.

curl_setopt($this->ch, CURLOPT_USERPWD, "USERNAME:PASSWORD");

And it worked. So point here is you can try this or play around with your curl/socket or any client you are building and don't focus on the error message as it is misleading most of the time. Hope this helps. Cheerz, Big J