해결된 질문
작성
·
667
·
수정됨
0
// 오픈웨더 API
const weatherSearch = function(position) {
console.log(position.latitude);
const openWeatherRes = fetch(
`https://api.openweathermap.org/data/2.5/onecall?lat=${position.latitude}&lon=${position.longitude}&appid=a0fe4b649d353a27a301be4b66d4173c`
);
console.log(openWeatherRes);
// 구분
};
// 현재 위치 함수
const accessToGeo = function (position) {
const positionObj = {
latitude : position.coords.latitude,
longitude : position.coords.longitude,
};
weatherSearch(positionObj);
};
// 사용자 현재 위치
const askForLocation = function (){
navigator.geolocation.getCurrentPosition(accessToGeo, (err) =>{
console.log(err);
} );
};
;
askForLocation();
현재 코드가 이렇게 되는데 401 오류가 뜨고 있습니다
// 오픈웨더 API
const weatherSearch = function(position) {
console.log(position.latitude);
const openWeatherRes = fetch(
`https://api.openweathermap.org/data/2.5/onecall?lat=${position.latitude}&lon=${position.longitude}&appid=a0fe4b649d353a27a301be4b66d4173c`
);
console.log(openWeatherRes);
// 구분
};
해당 코드에서
$ 부분이 오류가 뜨고 있기도 한데...
api는 default를 사용하였습니다
몇시간 강의 다시 보면서 뭐 잘못된 거 있나 해봐도 안 되서 이렇게 글 올려봐요
콘솔창 에러 메시지입니다
답변 1
0
안녕하세요! ㅋㅋㅋㅋㅋㅋ님!
openweather API는 2.5, 3.0 버전이 크게 구분되어 있습니다!
요청하신 API는 oncall? 로 시작되는 것으로 보아 3.0 에서 기본적으로 제공되는 API인 것 같아요!
2.5에서 제공되는 API는 weather? 로 시작합니다!
따라서, 숫자만 2.5로 변경하시는 것이 아닌, 2.5에서 제공되는 API를 사용해 주셔야 할 것 같아요!
해당 주소는 openweather API DOCS 에서 확인할 수 있어요!^^
오 정말 감사합니다 해결되었어요