我正在尝试将API密钥添加到下面的“获取”请求中吗?我有一个示例,下面没有API密钥。
这是我应该解析JSON的Node.js代码。
{ await getRemoteData(''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'
}')
.then((response) => {
const data = JSON.parse(response);
outputSpeech = `This is the name ${data[2].name} man look at that on a saturday morning.`;
}
有关上述GET请求的信息,请参见JSON格式。 这是API URL,但是您需要一个API密钥才能访问它。
JS eval
{
"0":{
"type":"coin",
"logoFile":"logos\/1.png",
"name":"Bitcoin",
"symbol":"BTC",
"price":5336.7412403400003313436172902584075927734375,
"marketcap":94232174265.99346923828125,
"volume":12689683492.3271999359130859375,
"rank":1,
"change":{
"hour":-0.0089407500000000007800426971016349853016436100006103515625,
"day":-0.139828000000000007840839089112705551087856292724609375,
"week":5.0347799999999995890220816363580524921417236328125
}
},
"1":{
"type":"coin",
"logoFile":"logos\/1027.png",
"name":"Ethereum",
"symbol":"ETH",
"price":172.80222112600000627935514785349369049072265625,
"marketcap":18273315192.039081573486328125,
"volume":5874660289.064609527587890625,
"rank":2,
"change":{
"hour":-0.11684999999999999553690344100687070749700069427490234375,
"day":-1.2512700000000001043787278831587173044681549072265625,
"week":5.626129999999999853343979339115321636199951171875
}
},
await getRemoteData('https://api.coinmarketcap.com/v1/ticker/')
.then((response) => {
const data = JSON.parse(response);
outputSpeech = `This is the name ${data[2].name} man look at that on a saturday morning.`;
})
这是下面的API链接。
[
{
"id": "bitcoin",
"name": "Bitcoin",
"symbol": "BTC",
"rank": "1",
"price_usd": "5260.8494713",
"price_btc": "1.0",
"24h_volume_usd": "13764287489.0",
"market_cap_usd": "92951055841.0",
"available_supply": "17668450.0",
"total_supply": "17668450.0",
"max_supply": "21000000.0",
"percent_change_1h": "0.14",
"percent_change_24h": "-0.28",
"percent_change_7d": "-1.42",
"last_updated": "1556377650"
},
{
"id": "ethereum",
"name": "Ethereum",
"symbol": "ETH",
"rank": "2",
"price_usd": "156.835413228",
"price_btc": "0.02983922",
"24h_volume_usd": "6040899613.44",
"market_cap_usd": "16598483757.0",
"available_supply": "105833774.0",
"total_supply": "105833774.0",
"max_supply": null,
"percent_change_1h": "0.45",
"percent_change_24h": "1.04",
"percent_change_7d": "-9.81",
"last_updated": "1556377642"
},
{
"id": "ripple",
"name": "XRP",
"symbol": "XRP",
"rank": "3",
"price_usd": "0.2965559184",
"price_btc": "0.00005642",
"24h_volume_usd": "890277280.659",
"market_cap_usd": "12456821485.0",
"available_supply": "42004966728.0",
"total_supply": "99991643723.0",
"max_supply": "100000000000",
"percent_change_1h": "0.21",
"percent_change_24h": "0.8",
"percent_change_7d": "-10.2",
"last_updated": "1556377622"
},