我正在学习如何使用RapidAPI,我也遇到了同样的问题。我正在尝试使用随机著名的引号和JavaScript fetch。我复制以下代码:
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会导致如下错误:"message":“缺少RapidAPI应用密钥。请转到https://docs.rapidapi.com/docs/keys了解如何获取您的API应用密钥。”
api密钥似乎丢失了,但据我所知,它是在fetch headers中提供的。这是语法错误还是我漏掉了什么?提前谢谢。
发布于 2021-08-26 16:56:53
这段代码对我来说运行得很好。
fetch("https://andruxnet-random-famous-quotes.p.rapidapi.com/?cat=movies&count=10", {
"method": "POST",
"headers": {
"x-rapidapi-host": "andruxnet-random-famous-quotes.p.rapidapi.com",
"x-rapidapi-key": "fdb84465dfmsh5c2245c197e72f7p1cf738jsnabb992bd3635"
}
})
.then(response => {
console.log(response);
})
.catch(err => {
console.error(err);
});如果仍然不起作用并且错误仍然存在,我建议您在RapidAPI Developer Dashboard上轮换您的API密钥或为您生成一个新的API密钥,因为您已经在您的问题中公开了您的API密钥。
https://stackoverflow.com/questions/61204257
复制相似问题