![](/img/trans.png)
[英]Fatal error for WooCommerce Rest API "PUT" request (update product)
[英]WooCommerce REST API Fatal Error Connection Issue
我正在嘗試使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());
}
?>
這是我得到的:
致命錯誤:未捕獲的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-> processResponse()#1 / Applications / MAMP / htdocs / WC_REST / vendor / automattic /woocommerce/src/WooCommerce/Client.php(82):Automattic \\ WooCommerce \\ HttpClient \\ HttpClient-> request('','GET',Array,Array)#2 /Applications/MAMP/htdocs/WC_REST/test.php (19):第346行上的/Applications/MAMP/htdocs/WC_REST/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php中引發了Automattic \\ WooCommerce \\ Client-> get('')#3 {main}
我准確記錄了文檔中的內容。
我總是在此服務器上找不到“ / wp-json / wc / v2 / system_status”。 如上所示,啟用$ body的輸出時出錯。
我修復了啟用永久鏈接(在admin-后端)的問題,該鏈接是訪問以斜杠分隔的URL所必需的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.