天气接口 Apixu 的简介

作者: DoubleThunder | 来源:发表于2017-06-14 16:14 被阅读362次

    介绍一个比较有实用的天气接口。地址 :https://www.apixu.com/

    先说明一下他的一些优势:

    0.免费,但有次数限制(5000次/月);
    1.可查询多个国家城市的天气情况;
    2.可查询多达 30 天的历史天气;
    3.可查询 10 天内的天气预报,并包括每小时的天气情况。
    4.当然也可以查询当天实现天气情况。
    5.有比较全的数据字段,并且可自选是否返回。
    

    当然有也一些不方便的地方。这个接口是国外的,请求接口所花时间较长。有时他们接口也会自行维护,但没有发送邮箱。次数限制 5000 次/月。不过总的来说,做开源项目,或者个人项目是不错的。但不建议商用。说到这,安利一个用 Apixu 接口做的天气应用 SimpleWeather

    简单使用

    首先简单登录注册后,打开个人主页得到 Api Key, 之后就可以 happy 的使用了。


    loginlogin mymy

    个人体验接口:
    实时天气:http://api.apixu.com/v1/current.json?key=bd6cf545b42d43cb96184023172905&lang=zh&q=beijing
    7天内的天气预报:https://api.apixu.com/v1/forecast.json?key=bd6cf545b42d43cb96184023172905&lang=zh&q=beijing&days=7


    相关接口说明

    0.请求说明

    0.1 请求 URL

    请求 Apixu API 由基础 URL 和 API 方法组成。 您可以向 API 发出 HTTP 或 HTTPS 请求。
    基础 URL : http://api.apixu.com/v1

    API API Method
    Current weather /current.json or /current.xml
    Forecast /forecast.json or /forecast.xml
    Search or Autocomplete /search.json or /search.xml
    History /history.json or /history.xml

    0.2 请求参数

    <table>
    <tr>
    <th>Parameter</th>
    <th> </th>
    <th>Description</th>
    </tr>
    <tr>
    <td>key</td>
    <td>Required</td>
    <td>API Key</td>
    </tr>
    <tr>
    <td> q </td>
    <td>Required</td>
    <td>
    查询城市对应的参数。

    1.经纬度 e.g: q=48.8567,2.3508

    2.城市名称 e.g.: q=Paris

    3.美国邮编 e.g.: q=10001

    4.英国邮编 e.g: q=SW1

    5.加拿大邮政编码 e.g: q=G2J

    6.metar:metar code e.g: q=metar:EGLL

    7.iata:3 digit airport code e.g: q=iata:DXB

    8.auto:ip IP lookup e.g: q=auto:ip

    9.IP address (IPv4 and IPv6 supported) e.g: q=100.0.0.1

    </td>
    <tr>
    <td>days</td>
    <td>仅用于预测 API 请求</td>
    <td>
    需要预测的天数。


    天参数值范围介于1到10。 e.g:days= 5


    如果没有提供天数参数,那么仅返回今天的天气。</td>
    </tr>
    <tr>
    <td>dt (历史 API 必要参数)</td>
    <td>用于限制 history and forecast API 天气日期输出(格式为 yyyy-MM-dd)</td>
    <td>
    1. history API 用于检当天历史天气

    2. forecast API 用于限制查询,今天到输入的日期之间。
    </td>
    </tr>
    <tr>
    <td>unixdt(可选项)</td>
    <td>用于限制 history and forecast API 的 Unix 时间戳。</td>
    <td>
    unixdt 与 dt 参数具有相同的限制。 请通过'dt'或'unixdt',而不是在同一请求中。e.g:unixdt = 1490227200。
    </td>
    </tr>

    <tr>
        <td> end_dt (可选项,可用于 history API)</td>
        <td>限制 forecast API 的日期输出(格式为 yyyy-MM-dd)</td>
        <td>
     对于 history API(dt = 2015-01-01)在 2015 年 1 月 1 日或之后。<br/>
    

    'end_dt'应该大于'dt'参数,两个日期之间不应超过30天。
    </td>
    </tr>

    <tr>
        <td> unixend_dt (可选项)</td>
        <td>用于 forecast API </td>
        <td>
    unixend_dt 与 end_dt 参数具有相同的限制。<br/> 请通过 end_dt 或 unixend_dt ,而不是两者都在相同的请求中。 例如:unixend_dt = 1490227200
        </td>
    </tr>
    
    <tr>
        <td> hour (可选项)</td>
        <td> 将 history or forecast 输出限制在指定日期的特定时间。
    

    </td>
    <td>
    hour 取值必须在 24 小时内。 例如:下午 5 点应该是 hour = 17,早上 6 点,hour = 6
    </td>
    </tr>

    <tr>
        <td> lang (可选项)</td>
        <td> "condition:text" 的返回参数中的语言
    

    </td>
    <td>
    从下表(0.3)中选择 "lang code" e.g.: lang=zh
    </td>
    </tr>

    </tr>
    

    </table>

    0.3 可选国家对应 lang code

    Language lang code
    Arabic ar
    Bengali bn
    Bulgarian bg
    Chinese Simplified zh
    Chinese Traditional zh_tw
    Czech cs
    Danish da
    Dutch nl
    Finnish fi
    French fr
    German de
    Greek el
    Hindi hi
    Hungarian hu
    Italian it
    Japanese ja
    Javanese jv
    Korean ko
    Mandarin zh_cmn
    Marathi mr
    Polish pl
    Portuguese pt
    Punjabi pa
    Romanian ro
    Russian ru
    Serbian sr
    Sinhalese si
    Slovak sk
    Spanish es
    Swedish sv
    Tamil ta
    Telugu te
    Turkish tr
    Ukrainian uk
    Urdu ur
    Vietnamese vi
    Wu (Shanghainese) zh_wuu
    Xiang zh_hsn
    Yue (Cantonese) zh_yue
    Zulu zu

    1. 当前最新天气情况

    1.0 返回总览

    名称 类型 说明
    location element 位置信息
    current element 当前天气情况

    1.1 current Element(当前天气)

    名称 类型 说明
    last_updated string 最后实时数据更新时间 e.g 2017-05-29 11:56
    last_updated_epoch int 最后实时数据更新时间 (1496051817)
    temp_c decimal 温度(摄氏 celsius)
    temp_f decimal 温度(华氏 fahrenheit)
    feelslike_c decimal 人体舒适度(摄氏)
    feelslike_f decimal 人体舒适度(华氏)
    condition:text string 天气描述(e.g:晴)
    condition:icon string 天气图标
    condition:code int 天气编码
    wind_mph decimal 风速(英里/h)
    wind_kph decimal 风速(km/h)
    wind_degree int 风的角度
    wind_dir string 风向 16 方位图
    pressure_mb decimal 大气压强(mb)
    pressure_in decimal 大气压强(英寸)
    precip_mm decimal 降水量(毫米)
    precip_in decimal 降水量(英寸)
    humidity int 湿度百分比
    cloud int 云层的百分比
    is_day int 是否显示日期图标或夜晚图标

    1.2 location Element(位置信息)

    名称 类型 说明
    name String 城市名称
    region String 区域
    country String 国家名称
    lat decimal 经度
    lon decimal 纬度
    tz_id String 时区 e.g: Asia/Shanghai
    localtime_epoch int 最后更新时间戳(毫秒)
    localtime String 最后更新时间(2017-05-30 3:06)

    2.Forecast and History 天气预报与历史天气

    因为请求返回的参数格式是一致的。所以到这个放在一起了

    2.0 返回总览

    名称 类型 说明
    location element 位置信息(参照 1.2)
    current element 当前天气情况(参照 1.1)
    forecastday element 天气预报

    2.1 forecastday element (天气预报)

    名称 类型 说明
    date string 预报日期(2017-05-30)
    date_epoch int 预报日期(1496102400)
    day element 具体这一天的情况
    astro element 这天的天文情况
    hour element 具体每小时内的天气情况

    2.2 day Element 类型数据

    名称 类型 说明
    maxtemp_c decimal 当天最高温度(摄氏)
    maxtemp_f decimal 当天最低温度(华氏)
    mintemp_c decimal 当天最高温度(摄氏)
    mintemp_f decimal 当天最低温度(华氏)
    avgtemp_c decimal 当前的平均温度(摄氏)
    avgtemp_f decimal 当前的平均温度(华氏)
    maxwind_mph decimal 最大风速(mile/h)
    maxwind_kph decimal 最大风速(km/h)
    totalprecip_mm decimal 总降水量(毫米)
    totalprecip_in decimal 总降水量(英寸)
    avgvis_km decimal 平均可见度(公里)
    avgvis_miles decimal 平均可见度(英里)
    avghumidity int 平均湿度(百分比)
    condition:text string 天气描述(晴)
    condition:icon string 天气图标
    condition:code int 天气编码

    2.3 astro Element 天文元素详细

    名称 类型 说明
    sunrise string Sunrise time
    sunset string Sunset time
    moonrise string Moonrise time
    moonset string Moonset time

    2.4 hour Element 每小时天气详情

    名称 类型 说明
    time_epoch int 时间点毫秒(1496073600)
    time string 时间点(2017-05-30 00:00)
    temp_c decimal 温度(摄氏)
    temp_f decimal 温度(华氏)
    condition:text string Weather condition text
    condition:icon string Weather condition icon
    condition:code int Temperature in code
    wind_mph decimal 最大风速(英里/小时)
    wind_kph decimal 最大风速(千里/小时)
    wind_degree int 风的方向角度
    wind_dir string 风的编码。 e.g.: NSW
    pressure_mb decimal 大气压强(mb)
    pressure_in decimal 大气压强(英寸)
    precip_mm decimal 降水量(毫米)
    precip_in decimal 降水量(英寸)
    humidity int 温度(百分比)
    cloud int 云层(百分比)
    feelslike_c decimal 人体舒适度指数(摄氏)
    feelslike_f decimal 人体舒适度指数(华氏)
    windchill_c decimal 风寒指数(摄氏)
    windchill_f decimal 风寒指数(华氏)
    heatindex_c decimal 热指数(摄氏)
    heatindex_f decimal 热指数(华氏)
    dewpoint_c decimal 露点(摄氏)
    dewpoint_f decimal 露点(华氏)
    will_it_rain int 是否会下雨(1,是;0,否)
    will_it_snow int 是否会下雪(1,是;0,否)
    is_day int 是否显示日期图标或夜晚图标(1,是;0,否)
    vis_km decimal 可见度(公里)
    vis_miles decimal 可见度(英里)

    ERRORS 错误码

    如果有错误,API 响应包含错误消息,包括以下 4xx HTTP 状态代码的错误代码。

    HTTP Status Code Error code Description
    401 1002 API key not provided.
    400 1003 Parameter 'q' not provided.
    400 1005 API request url is invalid
    400 1006 No location found matching parameter 'q'
    401 2006 API key provided is invalid
    403 2007 API key has exceeded calls per month quota.
    403 2008 API key has been disabled.
    400 9999 Internal application error.

    返回错误信息

    {"error":{"code":1005,"message":"API URL is invalid."}}
    

    相关文章

      网友评论

        本文标题:天气接口 Apixu 的简介

        本文链接:https://www.haomeiwen.com/subject/ulxeqxtx.html