接入教程
https://api.seniverse.com/v3/weather/now.json?key=你的私钥&location=beijing&language=zh-Hans&unit=c1. 注册心知天气账号并在控制台添加天气数据API产品。
2. 获取密钥(uid公钥与key私钥)。
3. 调用实时天气接口:
4. location支持城市名、经纬度或ip自动定位。
5. 免费版每天500次请求,开发阶段建议加缓存。
Python 获取实时天气
python
import requests
url = "https://api.seniverse.com/v3/weather/now.json"
params = {"key": "你的私钥", "location": "beijing", "language": "zh-Hans", "unit": "c"}
print(requests.get(url, params=params).json()["results"][0]["now"])
PHP 获取实时天气
php
<?php
$url = 'https://api.seniverse.com/v3/weather/now.json?key=你的私钥&location=beijing&language=zh-Hans&unit=c';
$data = json_decode(file_get_contents($url), true);
print_r($data['results'][0]['now']);
JavaScript 获取实时天气
javascript
fetch('https://api.seniverse.com/v3/weather/now.json?key=你的私钥&location=beijing&language=zh-Hans&unit=c')
.then(r => r.json())
.then(d => console.log(d.results[0].now));
常见问题
免费版每天多少请求?
免费版每天500次请求,适合个人开发与原型。
支持IP自动定位吗?
支持,将location参数设为ip即可根据请求来源IP定位。
Aitishiku.com