我正在尝试从FreeCodeCamp构建一个非常简单的项目,该项目使用API信息来传递天气信息。我正在使用Heroku App,以便能够在仍然是本地主机的情况下使用该API。但是,我收到2个错误,而且我不确定如何解决此问题。有帮助吗?
window.addEventListener("load", ()=> {
let long;
let lat;
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(position => {
long = position.coords.longitude;
lat = position.coords.latitude;
const proxy=`https://cors-anywhere.herokuapp.com/`;
const api=`${proxy}https://api.openweathermap.org/data/2.5/onecall?lat=${lat}&lon=${long}&
exclude={part}&appid={bdd50c9439280eb7362c1f796ce614ae}`;
fetch(api)
.then(response =>{
return response.json();
})
.then(data =>{
console.log(data);
})
});
}else {
h1.textContent = "hey dis is not working because not enabled"
};
});
* {
margin:0;
padding:0;
box-sizing:border-box;
}
body {
height:100vh;
display:flex;
justify-content: center;
flex-direction: column;
align-items: center;
background: linear-gradient(rgb(47,150,163),rgb(48,62,143));
font-family: sans-serif;
color:white;
}
.location,.temperature {
height: 30vh;
width:50%;
display:flex;
justify-content: space-around;
align-items: center;
}
.temperature{
flex-direction: column;
}
.degree-section {
display: flex;
align-items: center;
cursor: pointer;
}
.degree-section span{
margin: 10px;
font-size:30px
}
.degree-section h2{
font-size: 40px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge"/>
<link rel="stylesheet" href="./style.css"/>
<title>Document</title>
</head>
<body>
<div class="location">
<h1 class="location-timezone">Timezone</h1>
<p>Icon</p>
</div>
<div class="temperature">
<div class="degree-section">
<h2 class="temp-degree">34</h2>
<span>F</span>
</div>
<div class="temp-description">It's friggin cold</div>
</div>
<script src="app.js"></script>
</body>
</html>
答案 0 :(得分:1)
HTTP 429
Too many requests
响应状态代码表示用户在给定的时间内发送了太多请求(“速率限制”)。
您需要检查实际限制是多少,并且可能避免在页面加载时进行调用或超出其值。