4 api api-key http-status-code-401 flutter openweathermap
我正在尝试对 OpenWeatherMap 进行 API 调用。flutter run当我在终端中执行时,尽管我已经以适当的方式生成了 API 密钥并且它处于活动状态并正确复制,但打印出的是无效 API 密钥的代码response.statusCode。401
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,
);
}
}
Run Code Online (Sandbox Code Playgroud)
Flutter 的地理定位器包用于分配纬度和经度。如何401纠正错误?