我正在学习如何使用 RapidAPI,我遇到了同样的问题。我正在尝试将 Random Famous 引号与 JavaScript 提取一起使用。我复制这段代码:
async componentDidMount() {
await fetch("https://andruxnet-random-famous-quotes.p.rapidapi.com/?count=10&cat=movies", {
"method": "POST",
"headers": {
"x-rapidapi-host": "andruxnet-random-famous-quotes.p.rapidapi.com",
"x-rapidapi-key": "5d4682bb48msh8e662b997230c75p180ff3jsne9e95966eb37",
"content-type": "application/x-www-form-urlencoded"
},
"body": {}
})
.then(response => {
console.log(response);
})
.catch(err => {
console.log(err);
});
在控制台中,这是响应:
body: ReadableStream { locked: false }
bodyUsed: false
headers: Headers { }
ok: true
redirected: false
status: 200
statusText: "OK"
type: "cors"
url: "https://andruxnet-random-famous-quotes.p.rapidapi.com/?count=10&cat=movies"
该 url 导致错误:“消息”:“缺少 RapidAPI 应用程序密钥。转到https://docs.rapidapi.com/docs/keys了解如何获取您的 API 应用程序密钥。”
似乎缺少 api 密钥,但据我所知,它是在 fetch 标头中提供的。这是语法错误还是我缺少的其他东西?提前致谢。