inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

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

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

해결된 질문

766

ᄏᄏᄏᄏᄏᄏ

작성한 질문수 1

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

콘솔창 에러 메시지입니다

'code' 'js'

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

 

0

ᄏᄏᄏᄏᄏᄏ

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

수업 잘 들었습니다.

2

24

2

맥유저 입장의 고려해주세요

2

67

1

실행과정 질문입니다.

2

21

1

케이테스트 서버 운영 방법

2

52

1