I tried to use this function to get weather forecast data to return a data frame containing 5-day weather forecasts for a list of cities but I do not know what is missing. Here I using openweathermap.org for the weather data but I can not get it right.
cities <- c("Seoul", "Washington, D.C.", "Paris", "Suzhou")
# Get forecast data for a given city list
get_weather_forecaset_by_cities <- function(city_names){
df <- data.frame()
for (city_name in city_names){
# Forecast API URL
forecast_url <- 'https://api.openweathermap.org/data/2.5/forecast'
# Create query parameters
forecast_query <- list(q = city_name, appid = "{your_api_key}", units="metric")
# Make HTTP GET call for the given city
# Note that the 5-day forecast JSON result is a list of lists. You can print the reponse to check the results
#results <- json_list$list
# Loop the json result
for(result in results) {
city <- c(city, city_name)
}
# Add the R Lists into a data frame
}
# Return a data frame
return(df)