心知天气
天气插件
JS代码,用于将插件插入到网页内 : 天气插件文档
1.注册账号并添加产品
2.打开天气插件文档
选择自己组合
API接口
也可以调用接口 需要自定义样式 天气样式,可以通过
fetch链接自己博客
发送请求 获取对应城市
天气。 API接口文档
//心知天气提供API
https://api.seniverse.com/v3/weather/now.json?key=your_api_key&location=beijing&language=zh-Hans&unit=c
//修改后加入aip_key和城市名称即可构成可用API
https://api.seniverse.com/v3/weather/now.json?key=SKmg2uxKdER08RUk-&location=北京&language=zh-Hans&unit=c
// 代码案例
function sendFetchRequest() {
var apiKey = 'yourKey';
var location = '上海';
var language = 'zh-Hans';
var unit = 'c';
var params = {
key: apiKey,
location: location,
language: language,
unit: unit
};
// var url = new URL("https://api.seniverse.com/v3/weather/now.json");
// url.search = new URLSearchParams(params).toString();
var url = "https://api.seniverse.com/v3/weather/now.json?key=yourKey&location=上海&language=zh-Hans&unit=c"
fetch(url)
.then(response => response.json())
.then(data => console.log(data)) // 在控制台中打印响应数据
.catch(error => console.log(error));
}