인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

인프런 커뮤니티 질문&답변

ᄏᄏᄏᄏᄏᄏ님의 프로필 이미지
ᄏᄏᄏᄏᄏᄏ

작성한 질문수

[코드캠프] 부트캠프에서 만든 고농축 프론트엔드 코스

오픈웨더 api 관련 문제가 생겼습니다

해결된 질문

작성

·

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.jpg

api는 default를 사용하였습니다

 

몇시간 강의 다시 보면서 뭐 잘못된 거 있나 해봐도 안 되서 이렇게 글 올려봐요

api5.jpg

콘솔창 에러 메시지입니다

답변 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 에서 확인할 수 있어요!^^

 

오 정말 감사합니다 해결되었어요

ᄏᄏᄏᄏᄏᄏ님의 프로필 이미지
ᄏᄏᄏᄏᄏᄏ

작성한 질문수

질문하기