Я хочу импортировать данные openweather в мой файл.
Я хочу найти в Тбилиси шоу id
в текстовом теге.
Запрос не выполнен с кодом состояния 401
Ошибка:
- node_modules\axios\lib\core\createError.js:15:17 in createError
- node_modules\axios\lib\core\settle.js:16:9 in settle
- node_modules\axios\lib\adapters\xhr.js:52:6 in handleLoad
- node_modules\event-target-shim\dist\event-target-shim.js:818:39 in EventTarget.prototype.dispatchEvent
- node_modules\react-native\Libraries\Network\XMLHttpRequest.js:566:23 in setReadyState
- node_modules\react-native\Libraries\Network\XMLHttpRequest.js:388:25 in __didCompleteResponse
- node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:190:12 in emit
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:436:47 in __callFunction
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:111:26 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:384:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:110:17 in __guard$argument_0
* [native code]:null in callFunctionReturnFlushedQueue
Мой код:
const [term, setTerm] = useState("");
const [results, setResults] = useState([]);
const [errorMessage, setErrorMessage] = useState("");
const SearchApi = async () => {
try {
const response = await WeatherApi.get('/data', {
params: {
city: "",
id: "",
},
});
setResults(response.data.weather);
} catch (err) {
console.log(err);
setErrorMessage("Something went wrong!");
// setResults([]);
}
};
return (
<View>
<View
style={{ backgroundColor: "#000", width: "100%", height: 25 }}
></View>
<Header />
<SearchBar term={term} onTermChange={setTerm} onTermSubmit={SearchApi} />
<Button onPress={SearchApi} title="Submit" />
<Text>{errorMessage}</Text>
<Text>{results.id}</Text>
<Text>{}</Text>
</View>
);
};
Это топор ios файл
export default axios.create({
baseURL:
"https://api.openweathermap.org/data/2.5/weather?q={tbilisi}&appid={511581db0956bd0253fd9176a6038ade}",
headers: {
Authorization: "Bearer 511581db0956bd0253fd9176a6038ade",
},
});