这是我试图通过 Google 电子表格图表上的 JavaScript 工具运行的函数,该函数目前正在 4 个不同的网站上运行,在此示例中:
$id 是从我的电子表格单元格 (belacoin) 导入的值
function CoinmarketcapPrice($id) {
var response = UrlFetchApp.fetch("https://api.coinmarketcap.com/v1/ticker/" + $id);
var html = JSON.parse(response.getContentText());
try
{
return parseFloat(html["price_btc"]);
}
catch(err)
{
return null;
}
}
这是 UrlFetch 返回的内容:
[
{
"id": "belacoin",
"name": "BelaCoin",
"symbol": "BELA",
"rank": "176",
"price_usd": "0.212823",
"price_btc": "0.00008400",
"24h_volume_usd": "534995.0",
"market_cap_usd": "7694903.0",
"available_supply": "36156350.0",
"total_supply": "36156350.0",
"percent_change_1h": "0.63",
"percent_change_24h": "1.88",
"percent_change_7d": "-17.03",
"last_updated": "1499549044"
}
]
尝试 html.price_btc 或 html[0].price_btc
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句