I want to add weather widget to my react app, I'm trying to use React-Open-Weather lib. But the function that fetches the data useOpenWeather()
always responses with a 401
, I've confirmed my api-key is valid by putting it in the URL that is given in the documentation of react-open-weather. But I don't know what is wrong
`
Error: GET http://api.openweathermap.org/data/2.5/onecall?appid={apikey}&lang=en&units=metric&lat=48.137154&lon=11.576124 401 (Unauthorized)
My Code
import React from 'react'
import ReactWeather, { useOpenWeather } from 'react-open-weather';
const Weather = (props) => {
const { data, isLoading, errorMessage } = useOpenWeather({
key: 'myapikey',
lat: '48.137154',
lon: '11.576124',
lang: 'en',
unit: 'metric', // values are (metric, standard, imperial)
});
return (
<div>
<ReactWeather
isLoading={isLoading}
errorMessage={errorMessage}
data={data}
lang="en"
locationLabel="Munich"
unitsLabels={{ temperature: 'C', windSpeed: 'Km/h' }}
showForecast
/>
</div>
)
}
export default Weather
I tried re-installing the React-Open-Weather lib but that doesn't fix the problem
The URL that I used to confirm my api key: http://api.openweathermap.org/data/2.5/forecast?id=524901&appid={apikey}