uniapp 微信小程序授權登錄getUserInfo獲取不到用戶的昵稱和頭像
1、之前的授權用戶頭像個昵稱方法:
但如今,卻只能得到一個缺省的灰色頭像,和nickname = “微信用戶”,兩個數(shù)據(jù),其它的年齡以及地區(qū)等什么都沒有,更別提授權彈出框了
查看官網(wǎng)如下圖才知道API更新了:
基礎庫更新日志
獲取用戶信息接口變了,改用wx.getUserProfile(Object object)
https://developers.weixin.qq.com/miniprogram/dev/api/open-api/user-info/wx.getUserProfile.html
定位增加了頻率限制
https://developers.weixin.qq.com/community/develop/doc/000aee91a98d206bc6dbe722b51801?blockType=1
2.解決方案
uni.getUserProfile()
// 注意不能再 open-type="getUserInfo"
<text @click="getUserInfo">請登錄</text>
<script>
getUserInfo(){
console.log("一遍成功")
uni.getUserProfile({
desc:'Wexin', // 這個參數(shù)是必須的
success:res=>{
console.log(res)
},
fail:err=>{
console.log(err)
}
})
}
</script>