始終使用401 res在OpenWeather()中 - react-open-weather庫
<p>我想在我的React應用程式中新增天氣小工具,我嘗試使用React-Open-Weather庫。但是獲取資料的函數<code>useOpenWeather()</code>總是返回<code>401</code>,我透過將它放在react-open-weather文檔中提供的URL中確認了我的api-key是有效的。但我不知道出了什麼問題。 </p>
<blockquote>
<p>錯誤:GET http://api.openweathermap.org/data/2.5/onecall?appid=dc5807427c5379fdd34b63326ad4eb54&lang=en&units=metric&lat=48.1371548.13715448.134148.1370148.134148.48.1448.48. ;/p>
</blockquote>
<p><strong>我的程式碼</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>我嘗試重新安裝React-Open-Weather庫,但問題仍未解決。 </p>
<p>我用來確認我的api密鑰的URL:http://api.openweathermap.org/data/2.5/forecast?id=524901&appid=dc5807427c5379fdd34b63326ad4eb54</p>