Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.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
如何在OpenWeatherAPI中查找7天天气预报?_Api_Openweathermap - Fatal编程技术网

如何在OpenWeatherAPI中查找7天天气预报?

如何在OpenWeatherAPI中查找7天天气预报?,api,openweathermap,Api,Openweathermap,我正在尝试使用OpenWeatherAPI查找7天天气预报,但是当我调用OpenWeatherAPI时,当前位置的数据没有出现,有人能指导我找到正确的API来获取当前位置的天气预报吗 到目前为止使用的是API 1. api.openweathermap.org/data/2.5/forecast?q={city name}&appid={API key} 2. https://api.openweathermap.org/data/2.5/onecall?lat={lat}&lo

我正在尝试使用OpenWeatherAPI查找7天天气预报,但是当我调用OpenWeatherAPI时,当前位置的数据没有出现,有人能指导我找到正确的API来获取当前位置的天气预报吗

到目前为止使用的是API

1. api.openweathermap.org/data/2.5/forecast?q={city name}&appid={API key}
2. https://api.openweathermap.org/data/2.5/onecall?lat={lat}&lon={lon}&exclude={part}&appid={API key}
参考链接:

  • 请求:
    https://api.openweathermap.org/data/2.5/forecast?q=India&appid={MY_API_ID}
    答复:(在40个数据中只添加了2天的数据)


    你有很多问题,如果你能缩小范围,这将是有益的。但以下是我尽我所能提供帮助的最佳途径:

    对于7天预测,您需要申请7天预测。

    在您的示例中,请求
    1。api.openweathermap.org/data/2.5/forecast?q={city name}&appid={api key}
    您还包括了一个用于5天请求。如果您想要7天,这是个问题

    如果您想要5天的预测,您在第一个示例中引用的API需要一个城市名称,并且(如果您想包括一个国家),它要求国家名称在ISO 3166中,因此印度将是“印度”,而不是印度

    无论你想要5天还是7天,你都需要比印度更具体

    在5天的情况下,您需要一个城市名称。对于孟买的5天预测,您可以使用在第一个示例中尝试的API,如下所示:

      "https://api.openweathermap.org/data/2.5/forecast?q=mumbai&appid={yourAPIKey}"
    
       //includes lat and long for mumbai
     "https://api.openweathermap.org/data/2.5/onecall?lat=19.0760&lon=72.8777&appid={yourAPIkey}"
    
         
    
    如果是7天,则需要纬度和经度坐标。
    对于孟买的7天预测,您可以使用您在第二个示例中尝试的API,如下所示:

      "https://api.openweathermap.org/data/2.5/forecast?q=mumbai&appid={yourAPIKey}"
    
       //includes lat and long for mumbai
     "https://api.openweathermap.org/data/2.5/onecall?lat=19.0760&lon=72.8777&appid={yourAPIkey}"
    
         
    

    我希望这能回答您的问题。

    您能包括对API的请求和响应以及您收到的任何错误吗?您检索到API密钥了吗?如果没有,请按照步骤在此处获取一个。如果您刚刚开始,我建议您关注one call()API(因为它是免费的)。@elderlyman我收集了我的API密钥,但它没有显示当前位置的预测。无论我在哪个地方,每次都会有相同的回复。@ZachValenta我已经添加了请求和响应,请检查。请注意,您的请求包含
    q=India
    ,但您的回复返回的是
    “country”:“IT”
    “name”:“Innichen”
    。出于某种原因,如果你询问印度的结果,服务器会给出意大利一个名为Innichen的城市的结果。让我们澄清一下-你想要什么城市的名字?