我正在尝试调用OpenWeatherMap的API。当我在终端中执行
flutter run
时,response.statusCode
打印出401
,这是无效API密钥的代码,尽管我已经以适当的方式生成了API密钥,并且它已经激活并正确复制。const APIKey = '69f9afe03f52ef5c83887fc86dd79d99';
void getData() async {
http.Response response = await http.get(Uri.parse('https://api.openweathermap.org/data/3.0/onecall?lat=$latitude&lon=$longitude&appid=$APIKey'));
if (response.statusCode == 200) {
String data = response.body;
var decodedData = jsonDecode(data);
print(decodedData);
} else {
print(
response.statusCode,
);
}
}
在Flutter中使用Geolocator包来分配纬度和经度。如何纠正401
错误?