OpenWeatherMap 中的 API 密钥无效(错误 401)

4 api api-key http-status-code-401 flutter openweathermap

我正在尝试对 OpenWeatherMap 进行 API 调用。flutter run当我在终端中执行时,尽管我已经以适当的方式生成了 API 密钥并且它处于活动状态并正确复制,但打印出的是无效 API 密钥的代码response.statusCode401

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纠正错误?

Nin*_*d7N 9

checkout使用 OpenWeatherMap API 会出现 401 错误,您会在此处找到 apikey 无法工作的一些原因。另外,密钥激活需要2个小时。