강의

멘토링

커뮤니티

Cộng đồng Hỏi & Đáp của Inflearn

Hình ảnh hồ sơ của yunsa4855
yunsa4855

câu hỏi đã được viết

(Cập nhật mới nhất 2025) React: Bước cuối cùng để trở thành nhà phát triển Frontend

4. Lấy thông tin thời tiết dựa trên vị trí hiện tại

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

Viết

·

1.3K

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에러가 납니다....원인을 잘 모르겠어요!ㅠㅠ

reactreduxweb-api

Câu trả lời 1

0

codingnuna10082706님의 프로필 이미지
codingnuna10082706
Người chia sẻ kiến thức

안녕하세요 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

 

Hình ảnh hồ sơ của yunsa4855
yunsa4855

câu hỏi đã được viết

Đặt câu hỏi