简体   繁体   English

如何使用REST API从woocommerce检索订单详细信息?

[英]How to retrieve orders details from woocommerce using REST API?

I want to get orders details from woocommerce using REST API. 我想使用REST API从woocommerce获取订单详细信息。 If, I tried anything, it returns error like following: {"code":"woocommerce_rest_cannot_view","message":"Sorry, you cannot view this resource.","data":{"status":401}} 如果,我尝试了任何操作,它会返回如下错误:{“code”:“woocommerce_rest_cannot_view”,“message”:“抱歉,您无法查看此资源。”,“数据”:{“状态”:401}}

I have tried following, 我试过跟着,

require __DIR__ . '/vendor/autoload.php';

use Automattic\WooCommerce\Client;
use Automattic\WooCommerce\HttpClient\HttpClientException;

$woocommerce = new Client(
'https://www.domain.com', 
'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxXXXX', 
'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
    [
        'version' => 'v3',
    ]
);

print_r($woocommerce->get('orders'));

So, Please provide any suggestion or idea to acheive this solution. 所以,请提供任何建议或想法来实现这个解决方案。 Thanks in advance. 提前致谢。

HTTPS requests require Basic authentication (username and password), but HTTP requests require oAuth1 (encoding the secret and key). HTTPS请求需要基本身份验证(用户名和密码),但HTTP请求需要oAuth1(编码密钥和密钥)。

It's not immediately obvious in the documentation, but my answer to this question gives more details "cannot list resources" error from WooCommerce REST API 它在文档中并不是很明显,但我对这个问题的回答提供了更多细节“无法列出资源”错误来自WooCommerce REST API

Essentially, you need to change the secret and key to a base64 encoded "username:password" string (with the "Bearer" prefix) when using HTTPS. 实质上,您需要在使用HTTPS时将密钥和密钥更改为base64编码的“username:password”字符串(带有“Bearer”前缀)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM