前端jsonp调用百度天气接口,解决app禁用问题
接口示例接口:http://api.map.baidu.com/telematics/v3/weather?location=郑州&output=json&ak=jQDVWw8bEO7m2zMxR7ptfEcVQBbGyafeak获取前往百度申请ak:http://lbsyun.baidu.com/apiconsole/key经常有程序员申请完ak请求出现:app禁用的提示,主要是
·
接口
ak获取
前往百度申请ak:http://lbsyun.baidu.com/apiconsole/key
经常有程序员申请完ak请求出现:app禁用的提示,主要是因为申请时要选择“微信小程序”,不能选择”服务端“。
以下步骤:
选择小程序:
复制ak,替换掉上面的那个ak,就可以请求到数据了
先再地址栏输入看看能不能获取到:
结果:
{
"error": 0,
"status": "success",
"date": "2020-08-21",
"results": [
{
"currentCity": "北京",
"pm25": "50",
"index": [
{
"des": "天气热,建议着短裙、短裤、短薄外套、T恤等夏季服装。",
"tipt": "穿衣指数",
"title": "穿衣",
"zs": "热"
},
{
"des": "较适宜洗车,未来一天无雨,风力较小,擦洗一新的汽车至少能保持一天。",
"tipt": "洗车指数",
"title": "洗车",
"zs": "较适宜"
},
{
"des": "各项气象条件适宜,无明显降温过程,发生感冒机率较低。",
"tipt": "感冒指数",
"title": "感冒",
"zs": "少发"
},
{
"des": "天气较好,赶快投身大自然参与户外运动,尽情感受运动的快乐吧。",
"tipt": "运动指数",
"title": "运动",
"zs": "适宜"
},
{
"des": "紫外线辐射极强,建议涂擦SPF20以上、PA++的防晒护肤品,尽量避免暴露于日光下。",
"tipt": "紫外线强度指数",
"title": "紫外线强度",
"zs": "很强"
}
],
"weather_data": [
{
"date": "周五 08月21日 (实时:27℃)",
"dayPictureUrl": "http://api.map.baidu.com/images/weather/day/qing.png",
"nightPictureUrl": "http://api.map.baidu.com/images/weather/night/qing.png",
"weather": "晴",
"wind": "西风微风",
"temperature": "28 ~ 17℃"
},
{
"date": "周六",
"dayPictureUrl": "http://api.map.baidu.com/images/weather/day/duoyun.png",
"nightPictureUrl": "http://api.map.baidu.com/images/weather/night/yin.png",
"weather": "多云转阴",
"wind": "西南风微风",
"temperature": "28 ~ 19℃"
},
{
"date": "周日",
"dayPictureUrl": "http://api.map.baidu.com/images/weather/day/xiaoyu.png",
"nightPictureUrl": "http://api.map.baidu.com/images/weather/night/zhongyu.png",
"weather": "小雨转中雨",
"wind": "南风微风",
"temperature": "28 ~ 21℃"
},
{
"date": "周一",
"dayPictureUrl": "http://api.map.baidu.com/images/weather/day/duoyun.png",
"nightPictureUrl": "http://api.map.baidu.com/images/weather/night/duoyun.png",
"weather": "多云",
"wind": "北风3-4级",
"temperature": "32 ~ 20℃"
}
]
}
]
}
更多推荐
已为社区贡献4条内容
所有评论(0)