테스트 사이트 - 개발 중인 베타 버전입니다

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

박한 4년 전 조회 1,559

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

 

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

 

api센터에서 어떤내용을 보고 어떻게 작성해야하는지 방법을 알 수 이쓸까요..

 

 

</p>

<p>    <?php

        $url = '<a href="https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest';" target="_blank" rel="noopener noreferrer">https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest';</a>

        $parameters = [

          'start' => '1',

          'limit' => '5000',

          'convert' => 'KRW'

        ];</p>

<p>        $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</p>

<p>

        $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

        ));</p>

<p>        $response = curl_exec($curl); // Send the request, save the response

        print_r(json_decode($response)); // print json decoded response

        curl_close($curl); // Close request

        ?></p>

<p>

댓글을 작성하려면 로그인이 필요합니다.

답변 1개

채택된 답변
+20 포인트
4년 전

$result = json_decode($response);

echo $result->KRW->price;

 

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

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

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

박한
4년 전
<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>

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

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인