简体   繁体   English

WooCommerce REST API致命错误连接问题

[英]WooCommerce REST API Fatal Error Connection Issue

I'm trying to make woocommerce REST API work. 我正在尝试使woocommerce REST API正常工作。 On first sight it apears quite simple by following the doc: https://woocommerce.github.io/woocommerce-rest-api-docs/?php#introduction . 乍一看,通过遵循以下文档即可轻松实现: https ://woocommerce.github.io/woocommerce-rest-api-docs/?php#introduction。 But I struggle making it work. 但是我很难使它起作用。 Here is my code: 这是我的代码:

<?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());
}

?>

Here is what i get: 这是我得到的:

Fatal error: Uncaught Automattic\\WooCommerce\\HttpClient\\HttpClientException: Syntax error in /Applications/MAMP/htdocs/WC_REST/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php:346 Stack trace: #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): Automattic\\WooCommerce\\Client->get('') #3 {main} thrown in /Applications/MAMP/htdocs/WC_REST/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php on line 346 致命错误:未捕获的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}

I wrote down exactly what's in the doc. 我准确记录了文档中的内容。

I always got an '/wp-json/wc/v2/system_status was not found on this server.' 我总是在此服务器上找不到“ / wp-json / wc / v2 / system_status”。 error when enabling the output of $body as suggested above. 如上所示,启用$ body的输出时出错。

I fixed it with enabling permalinks (in admin-backend) which is needed for accessing a slash separated url. 我修复了启用永久链接(在admin-后端)的问题,该链接是访问以斜杠分隔的URL所必需的。

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

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