I want to add weather widget in my React application and I try to use React-Open-Weather library. But the function to get the data useOpenWeather()
always returns 401
which I confirmed by putting it in the URL provided in the react-open-weather documentation The api-key is valid. But I don't know what's wrong.
Error: GET http://api.openweathermap.org/data/2.5/onecall?appid=dc5807427c5379fdd34b63326ad4eb54&lang=en&units=metric&lat=48.137154&lon=11.576124 401 (Unauthorized)< ;/p>
My Code
import React from 'react' import ReactWeather, { useOpenWeather } from 'react-open-weather'; const Weather = (props) => { const { data, isLoading, errorMessage } = useOpenWeather({ key: 'dc5807427c5379fdd34b63326ad4eb54', lat: '48.137154', lon: '11.576124', lang: 'en', unit: 'metric', // values are (metric, standard, imperial) }); return () } export default Weather
I tried reinstalling the React-Open-Weather library, but the problem is still not resolved.
The URL I use to confirm my api key: http://api.openweathermap.org/data/2.5/forecast?id=524901&appid=dc5807427c5379fdd34b63326ad4eb54
According tohttps://openweathermap.org/api/one-call-api,
onecall
returns all possible functions:Some features, such as forecasts, are not allowed for free accounts. You can only get the current weather by running
weather
instead ofonecall
:And with your parameters, it displays the data correctly.