以下代码仅返回api.coinmarketcap.com的100条记录 我认为是由于api的最新更改。
$pMarket = "https://api.coinmarketcap.com/v1/ticker/?start=1&limit=300";
$fgc = json_decode(file_get_contents($pMarket), true);
$n = COUNT( $fgc );
echo "number of records:" .$n . "<br>" . PHP_EOL;
for($i=0;$i<$n;$i++){
$id = $fgc[$i]["id"];
echo $i+1 .":" .$id . "<br>" . PHP_EOL;
}
?>
结果:
number of records:100
1:ripple
2:ethereum
3:bitcoin-cash
...
98:loopring
99:zcoin
100:gxchain
我如何修改代码才能获得100多个记录?
基于新api的文档,以某种方式必须使用我的api密钥。
/* Example in Node.js ES6 using request-promise, concepts should translate to your language of choice */
const rp = require('request-promise');
const requestOptions = {
method: 'GET',
uri: 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest',
qs: {
start: 1,
limit: 5000,
convert: 'USD'
},
headers: {
'X-CMC_PRO_API_KEY': 'b54bcf4d-1bca-4e8e-9a24-22ff2c3d462c'
},
json: true,
gzip: true
};
rp(requestOptions).then(response => {
console.log('API call response:', response);
}).catch((err) => {
console.log('API call error:', err.message);
});
感谢任何提示。