코인마켓캡 정보 가져오는것은 해두었는데..

코인마켓캡 정보 가져오는것은 해두었는데..

QA

코인마켓캡 정보 가져오는것은 해두었는데..

본문

현재 모든 정보가 다 달라붙어서 쓸수가없습니다..

 

비트코인의 심볼, 가격, 등락 정도만 가져오려는데 방법을 모르겠어서요

 

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
        ?>

1025951730_1621932591.5464.jpg

이 질문에 댓글 쓰기 :

답변 1

$result = json_decode($response);

echo $result->KRW->price;

 

이런식으로 출력하시면 됩니다.

php object, stdclass에 관해 검색해보세요.

<code>
  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
echo $result->KRW->price;


?>
</code>

형태로 수정해도 똑같은 결과가 나오는데, 조금만 더 자세히 설명해주실 수 없을까요?
비트코인+이더리움의 특정 정보(심볼,시세,등락)를 가져오려합니다.

답변을 작성하시기 전에 로그인 해주세요.
전체 22
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT