• 카테고리

    질문 & 답변
  • 세부 분야

    프론트엔드

  • 해결 여부

    미해결

openweather api 호출 했는데 401가 나요!

23.01.12 20:00 작성 조회수 867

0

const getCurrentLocation = () => {
    navigator.geolocation.getCurrentPosition((position)=>{
      console.log('위치', position.coords.latitude, position.coords.longitude); // 위치 37.4838677 126.902839
      getWeatherByCurrentLocation(position.coords.latitude, position.coords.longitude); 
    });
  }

  const getWeatherByCurrentLocation = async(latitude, longitude) => {
    let apiKey = '0619cf6a981bec8d01375e5576139e86';
    let apiUrl = `https://api.openweathermap.org/data/3.0/onecall?lat=${latitude}&lon=${longitude}&appid=${apiKey}`;

    let response = await fetch(apiUrl);
    let data = await response.json();

    console.log('data', data);

  }
  
  useEffect(()=>{getCurrentLocation()}, []);

이렇게 작성해서 돌려보니

스크린샷 2023-01-12 오후 7.59.26.png이런식으로 401에러가 납니다....원인을 잘 모르겠어요!ㅠㅠ

답변 1

답변을 작성해보세요.

0

안녕하세요 3.0 버전은 유료버전이거나 따로 api를 발급받아야하는 것 같네요 2.5버전을 호출 부탁드립니다!

https://api.openweathermap.org/data/2.5/weather

추가 질문은 제 슬랙채널에서 해주세요!

https://join.slack.com/t/w1631756876-zfv299364/shared_invite/zt-w5yxap8g-~_Exi5lOwfw_N6a1T5djmg