我正在尝试使用woocommerce REST API。乍一看,按照文档https://woocommerce.github.io/woocommerce-rest-api-docs/?php#introduction进行操作非常简单。 但我努力使其发挥作用。 这是我的代码:
<?php
require __DIR__ . '/vendor/autoload.php';
use Automattic\WooCommerce\Client;
$woocommerce = new Client(
'my_website_uri',
'consumer_key',
'consumer_secret',
[
'wp_api' => true,
'version' => 'wc/v2'
]
);
try{
print_r($woocommerce->get(''));
}
catch (HttpClientException $e) {
print_r($e->getMessage());
print_r($e->getRequest());
print_r($e->getResponse());
}
?>
这是我得到的:
致命错误:Uncaught Automattic \ WooCommerce \ HttpClient \ HttpClientException:/Applications/MAMP/htdocs/WC_REST/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php:346中的语法错误堆栈跟踪:#0 / Applications / MAMP / htdocs / WC_REST / vendor / automattic / woocommerce / src / WooCommerce / HttpClient / HttpClient.php(385):Automattic \ WooCommerce \ HttpClient \ HttpClient-&gt; processResponse()#1 / Applications / MAMP / htdocs / WC_REST /vendor/automattic/woocommerce/src/WooCommerce/Client.php(82):Automattic \ WooCommerce \ HttpClient \ HttpClient-&gt; request('','GET',Array,Array)#2 / Applications / MAMP / htdocs / WC_REST / test.php(19):Automattic \ WooCommerce \ Client-&gt; get('')#3 {main}抛出/ Applications / MAMP / htdocs / WC_REST / vendor / automattic / woocommerce / src / WooCommerce / HttpClient /第346行的HttpClient.php
我写下了文档中的内容。
答案 0 :(得分:0)
我总是在这台服务器上找不到&#39; / wp-json / wc / v2 / system_status。&#39;启用$ body的输出时出错,如上所述。
我修复了启用固定链接(在admin-backend中),这是访问斜杠分隔网址所必需的。