Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振:请求url显示无效api_Flutter_Dart_Flutter Http - Fatal编程技术网

Flutter 颤振:请求url显示无效api

Flutter 颤振:请求url显示无效api,flutter,dart,flutter-http,Flutter,Dart,Flutter Http,我想要一份基于经纬度的当前位置的天气报告。以下是我的代码: void getData() async{ print("hello"); http.Response response = await http.get('https://api.openweathermap.org/data/2.5/weather?lat=$lat&lon=$lon&appid=$apis'); print(response.statusCode);

我想要一份基于经纬度的当前位置的天气报告。以下是我的代码:

void getData() async{
    print("hello");
    http.Response response = await http.get('https://api.openweathermap.org/data/2.5/weather?lat=$lat&lon=$lon&appid=$apis');
    print(response.statusCode);
    if(response.statusCode==200){
      String data = response.body;
      int id = jsonDecode(data)['weather'][0]['id'];
      double temperature = jsonDecode(data)['main']['temp'];
      String city = jsonDecode(data)['name'];
      print(id);
      print(temperature);
      print(city);
    }

    print(response.body);
  }
运行应用程序时,我出现以下错误,但我正确地遵循了说明,并使用了网站提供的api

{“cod”:401,“消息”:“无效的API密钥。有关详细信息,请参阅。”}

可能您的API密钥尚未激活?你应该等一段时间让它激活。是的,我现在拿到了。您是对的,api密钥需要时间才能激活谢谢@MangirdasKazlauskas