简体   繁体   English

在 Next.js 中从 API 获取数据时出现问题

[英]Problem fetching data from API in Next.js

Im trying to fetch some data from the popular Morningstar api. I'm using axios and also using their code example for javascript - axios.我试图从流行的Morningstar api 获取一些数据。我正在使用 axios 并且还使用他们的代码示例 javascript - axios。

My code looks like this:我的代码如下所示:

const options = {
  method: 'GET',
  url: 'https://morningstar1.p.rapidapi.com/dividends',
  params: {Ticker: 'MSFT', Mic: 'XNAS'},
  headers: {
    accept: 'string',
    'x-rapidapi-key': '700c7f0abamsh61a21d67f2579cdp1097e3jsn3fa403041f99',
    'x-rapidapi-host': 'morningstar1.p.rapidapi.com'
  }
};
useEffect(() => {
  axios.request(options).then(function (response) {
    console.log(response.data); // HERE I LOG THE DATA FROM API
  }).catch(function (error) {
    console.error(error);
  });
}, [])

And the error i get when i console logs response.data is:当我控制台日志 response.data 时得到的错误是:

https://gyazo.com/9d8a5defd87088cdeb8bc2823261d60f https://gyazo.com/9d8a5defd87088cdeb8bc2823261d60f

Anyone that has a solution to this error?任何人都可以解决此错误? Thank you!谢谢!

That is because you are not subscribed to this API: when running this code i got:那是因为你没有订阅这个 API:运行这段代码时我得到:

{"message":"You are not subscribed to this API."}

in the.network tab in the dev tool.在开发工具的.network 选项卡中。 here is an image这是一张图片在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM