0

こんにちは、JSON を使用して配列内のデータを POST して、応答を受け取り、応答を出力しようとしています。これまでのところ、すべてのパラメーターを厳密に追跡しましたが、データの取得に失敗しました。

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;

?>
4

1 に答える 1