0

我正在学习如何使用 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 标头中提供的。这是语法错误还是我缺少的其他东西?提前致谢。

4

1 回答 1

0

这段代码对我来说很好用。

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 密钥。

于 2021-08-26T16:56:53.240 回答