逐小时预报 168 小时
返回逐小时 168 小时天气预报数据,数据每小时更新一次。
接口地址
https://api.foreocean.com/weather/hourly/168h
请求方式
GET
请求参数说明
参数名称 | 类型 | 是否必须 | 备注 |
---|---|---|---|
Token | String | 是 | API 调用令牌,您申请应用的 Token,放在请求头中 |
location | String | 是 | 经纬度,经度在前,纬度在后,例如:120.398207,36.070148 |
version | String | 是 | 调用的接口版本,固定为:1.0 |
请求示例
java
public static void main(String[] args) {
Map<String, Object> params = new HashMap<>(16);
params.put("location", "118.996044,38.63521");
params.put("version", "1.0");
String requestUrl = "https://api.foreocean.com/weather/hourly/168h";
String response = get(requestUrl, params);
System.out.println(response);
}
public static String get(String url, Map<String, Object> params) {
try {
CloseableHttpClient httpClient = HttpClients.createDefault();
url = url + "?";
for (Iterator<String> iterator = params.keySet().iterator(); iterator.hasNext();) {
String key = iterator.next();
String temp = key + "=" + params.get(key) + "&";
url = url + temp;
}
url = url.substring(0, url.length() - 1);
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader("Token","API调用令牌");
CloseableHttpResponse response = httpClient.execute(httpGet);
try {
HttpEntity entity = response.getEntity();
if (entity != null) {
String str = EntityUtils.toString(entity, CHARSET);
return str;
}
} finally {
response.close();
httpClient.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
python
import requests
if __name__ == '__main__':
url = 'https://api.foreocean.com/weather/hourly/168h'
headers = {'Token': 'API调用令牌'}
params = {'location': '118.996044,38.63521','version': '1.0'}
response = requests.get(url, headers=headers, params=params)
print(response.text)
返回结果示例
{
"code": "1000", //响应码,1000-处理成功,其他代码说明请参考API返回错误代码说明
"data": [
{
"cityName": "Beijing",//城市名
"lon": "116.4658",//经度
"lat": "39.9191",//纬度
"dateTime": "2023-06-01 15",//数据更新时刻
"pod": "d",//白天还是夜晚 d:白天 n:夜晚
"visibility": 24.128,//能见度 km
"weatherDescription": "多云",//天气现象
"weatherCode": 1033,//天气代码 参考【海洋天气对照表】菜单
"clouds": 57,//云层量 %
"pressure": 993,//气压 mb
"probability": 0,//降雨概率 %
"precipitation": 0,//降雨量 mm/hr
"snowDepth": 0,//降雪厚度 mm
"snow": 0,//降雪量 mm/hr
"temperature": 31.1,//温度 摄氏度℃
"appTemp": 29.3,//体感温度 摄氏度℃
"seaPressure": 997.5,//海平面气压 mb
"ultravioletRays": 4.9,//紫外线指数 范围0-11
"rHumidity": 22,//相对湿度 %
"windDirection": 277,//风向角度度数
"windSpeed": 4.63,//风速 m/s
"windMark": "西"//风向描述
},
//...后续省略
],
"msg": "success", //返回信息描述
"success": true //请求是否成功,true表示成功,false表示失败
}