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