Home > Blockchain >  Getting API Key Invalid error in Flutter HTTP Request
Getting API Key Invalid error in Flutter HTTP Request

Time:08-30

I am trying to fetch weather data from enter image description here

What is wrong in my code, and how to solve the issue?

CodePudding user response:

try this:

String authority = "api.weatherapi.com";
String apiKey = "bc4512ff6799474cbcc114118222908";
String query = "london";
String unencodedPath = "v1/forecast.json";

final queryParameters = {
  'key': apiKey,
  'q': query,
  'days': 10,
  'aqi': 'yes',
  'alerts': 'yes',
  
};


Future getWeatherData() async {
  final uri = Uri.https(authority, unencodedPath, queryParameters);
 
  var response = await http.get(uri);;
  var jsonData = jsonDecode(response.body);
  print(jsonData);
}
  • Related