如何解决为什么它说我的 RapidAPI API 密钥无效?
我刚刚开始学习如何使用 API。对于我的第一个项目,我决定使用 RapidAPI 市场,但我遇到了问题。 我尝试在邮递员中测试 API,但它说由于某种原因我有一个无效的 API 密钥,即使我很确定我没有。在 chrome 控制台上,它给了我如图所示的错误:
它基本上是说服务器响应了状态 404 的错误。我还有一个配置文件来存储 api 密钥。它基本上是这样的:
const API_KEY = "randomlettersandnumbers";
export {API_KEY};
我在 VSCode 上使用 LiveServer 扩展。这是我的文件夹在 VSCode 上的样子:
我的其余代码如下所示:
import {API_KEY} from './config';
fetch("https://community-open-weather-map.p.rapidapi.com/weather?q=London%2Cuk&lat=0&lon=0&callback=test&id=2172797&lang=null&units=%22metric%22%20or%20%22imperial%22&mode=xml%2C%20html",{
"method": "GET","headers": {
"x-rapidapi-key": API_KEY,"x-rapidapi-host": "community-open-weather-map.p.rapidapi.com"
}
})
.then(response =>response.json())
.then(response => {
console.log(response);
console.log(response.content);
})
.catch(err => {
console.error(err);
});
<!doctype html>
<html lang="en">
<head>
<title>API Example</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
This better work!
<script src = "js/main.js" type = "module"></script>
</body>
</html>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。