Coinmarketcap 小部件未响应请求

Coinmarketcap widget is not responding to request

我正在使用此代码获取货币数据,如价格、市值等... 我正在准备新的机器人,由于 api 错误,请求无法正常工作...

代码:

'use strict';

const rp = require('request-promise');
const requestOptions = {
  method: 'GET',
  uri: 'https://3rdparty-apis.coinmarketcap.com/v1/cryptocurrency/widget?id=3501&convert=BTC,ETH,USD',
  headers: {
  json: true,
  gzip: true
  }
};

rp(requestOptions).then(response => {
  const answer = JSON.parse(response)
  console.log('API Call response:', answer["data"]["3501"]["quote"]);
}).catch((err) => {
  console.log('API Call error:', err.message);
});

错误: API Call error: 403 - "error code: 1020"

有什么想法吗? https://3rdparty-apis.coinmarketcap.com/v1/cryptocurrency/widget?id=3501&convert=BTC,ETH,USD

它工作得很好,当我在网络浏览器中输入 link 时,我可以看到所有数据。

将您的用户代理设置为:

'use strict';

const rp = require('request-promise');
const requestOptions = {
  method: 'GET',
  uri: 'https://3rdparty-apis.coinmarketcap.com/v1/cryptocurrency/widget?id=3501&convert=BTC,ETH,USD',
  headers: {
  json: true,
  gzip: true,
  'User-Agent': 'Discordbot/2.0'
  }
};