WooCommerce产品REST API的问题

问题描述 投票:-1回答:1

[我尝试使用WooCommerce rest api来获取并获得所有产品,但是当json数据返回时,它添加了新产品并仅返回名为"product"的新产品作为名称。

这是我的代码

define("TOKEN_API" , "eyJ0eXAiOiJKL1QiLCJhbGciOaJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9xd3cuaGFtaXRhay5jb20iLCJpYXQiOjE1ODcyMjUzNTQsIm5iZiI6MTU4NzIyNTM1NCwiZXhwIjoxNTg3ODMwMTU0LCJkYXRhIj17InVzZXIiOnsiaWQi1iI3In19fQ.9AhzaFJLX1B-x0KEwA0CH14v-5IaiEyEhCA-5sTeSQ8");

$url = "http://www.example.com" . "/wp-json/wc/v2/products";
$authorization = "Authorization: Bearer " . TOKEN_API;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization ));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec($ch);

curl_close ($ch);

$products = json_decode($server_output , true);

print_r($products);

是什么问题。我搜索了很多但没有找到。

php woocommerce woocommerce-rest-api
1个回答
0
投票

我终于找到了这是因为发布请求我现在使用get request及其罚款

© www.soinside.com 2019 - 2024. All rights reserved.