코인마켓캡 정보 가져오는것은 해두었는데..
본문
현재 모든 정보가 다 달라붙어서 쓸수가없습니다..
비트코인의 심볼, 가격, 등락 정도만 가져오려는데 방법을 모르겠어서요
api센터에서 어떤내용을 보고 어떻게 작성해야하는지 방법을 알 수 이쓸까요..
<?php
$url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest';
$parameters = [
'start' => '1',
'limit' => '5000',
'convert' => 'KRW'
];
$headers = [
'Accepts: application/json',
'X-CMC_PRO_API_KEY: a2e61c-bee32a6df'
];
$qs = http_build_query($parameters); // query string encode the parameters
$request = "{$url}?{$qs}"; // create the request URL
$curl = curl_init(); // Get cURL resource
// Set cURL options
curl_setopt_array($curl, array(
CURLOPT_URL => $request, // set the request URL
CURLOPT_HTTPHEADER => $headers, // set the headers
CURLOPT_RETURNTRANSFER => 1 // ask for raw response instead of bool
));
$response = curl_exec($curl); // Send the request, save the response
print_r(json_decode($response)); // print json decoded response
curl_close($curl); // Close request
?>
답변 1
$result = json_decode($response);
echo $result->KRW->price;
이런식으로 출력하시면 됩니다.
php object, stdclass에 관해 검색해보세요.
답변을 작성하시기 전에 로그인 해주세요.