您好我正在尝试使用 JSON 在数组中发布一些数据以接收响应并输出响应。到目前为止,我已经密切关注所有参数,但无法获取数据。
我正在使用 Coinbase API 来“生成”一个按钮 https://coinbase.com/api/doc/1.0/buttons.html
根据此页面,我还在下面的 $ch 变量中放入了正确的 API
https://coinbase.com/docs/api/authentication
它无法取回任何东西。我已经发布了正确的详细信息以获得一些数据的响应,但它失败了,有什么想法吗?
这是我的代码
<?php
$data = array(
"button" => array(
"name" => "Product Name",
"price_string" => "1.23",
"price_currency_iso" => "USD",
"custom" => "Order 123",
"description" => "Sample description",
"type" => "buy_now",
"style" => "custom_large"
)
);
$json_data = json_encode($data);
$ch = curl_init('https://coinbase.com/api/v1/buttons?api_key=MYAPIKEY');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($json_data))
);
$output = curl_exec($ch);
$result = json_decode($output);
echo $result->button->type;
?>