我正在开展一个辅助项目,并且我一直在尝试与WooCommerce REST API进行交互。
我的一切看似正确。我已经创建了正确的密钥,因为它们与cURL一起使用。但是当我尝试使用Automattic提供的php-wrapper时,一切都停止了。
我的代码设置与他们的指示完全一样: 需要 DIR 。 ' /../供应商/ autoload.php&#39 ;;
使用Automattic \ WooCommerce \ Client;
$woocommerce = new Client(
'https://mywebsitenamegoeshere.com',
'##########',
'##########',
[
'wp_api' => true,
'version' => 'wc/v2',
'query_string_auth' => true
]
);
我只是想尝试列出端点(也适用于cURL),但是一旦我尝试通过php-wrapper进行交互,我就会收到以下错误消息:
Fatal error: Uncaught exception 'Automattic\WooCommerce\HttpClient\HttpClientException' with message 'Syntax error' in /nas/content/live/wwitssltest/wp-content/themes/twentyseventeen/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php:346
Stack trace: #0 /nas/content/live/wwitssltest/wp-content/themes/twentyseventeen/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php(385): Automattic\WooCommerce\HttpClient\HttpClient->processResponse()
#1 /nas/content/live/wwitssltest/wp-content/themes/twentyseventeen/vendor/automattic/woocommerce/src/WooCommerce/Client.php(82): Automattic\WooCommerce\HttpClient\HttpClient->request('', 'GET', Array, Array)
#2 /nas/content/live/wwitssltest/wp-content/themes/twentyseventeen/ticket-data-test-template.php(15): Automattic\WooCommerce\Client->get('')
#3 /nas/content/live/wwitssltest/wp-includes/template-loader.php(74): include('/nas/content/li...')
#4 /nas/content/live/wwitssltest/wp-blog-header.php(19): require_once('/nas/content/li...')
#5 /nas/content in /nas/content/live/wwitssltest/wp-content/themes/twentyseventeen/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php on line 346
当我查看文件时,特别是HttpClient.php
我可能遇到的最具体的信息是JSON可能格式不正确吗?
documentation看起来非常干净,但我做的事情没有任何区别。
除了返回Client对象的<php print_r( $woocommerce ); ?>
之外。