Always use 401 res in OpenWeather() - react-open-weather library
<p>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 <code>useOpenWeather()</code> always returns <code>401</code> 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. </p>
<blockquote>
<p>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>
</blockquote>
<p><strong>My Code</strong></p>
<pre class="brush:php;toolbar:false;">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 (
<div>
<ReactWeather
isLoading={isLoading}
errorMessage={errorMessage}
data={data}
lang="en"
locationLabel="Munich"
unitsLabels={{ temperature: 'C', windSpeed: 'Km/h' }}
showForecast
/>
</div>
)
}
export default Weather</pre>
<p>I tried reinstalling the React-Open-Weather library, but the problem is still not resolved. </p>
<p>The URL I use to confirm my api key: http://api.openweathermap.org/data/2.5/forecast?id=524901&appid=dc5807427c5379fdd34b63326ad4eb54</p>