問題描述
小程序更改了調用用戶信息的接口,詳情
調用getUserProfile直接進入失敗
返回的錯誤信息如下
getUserProfile:fail can only be invoked by user TAP gesture.
大概意思是此接口只能通過用戶點擊調用
修改
我們稍作調整,使用按鈕進行調用
wx.showModal({
title: '溫馨提示',
content: '親,授權微信登錄後才能正常使用小程序功能',
success(res) {
console.log(0)
console.log(res)
//如果用戶點擊了確定按鈕
if (res.confirm) {
wx.getUserProfile({
desc: '獲取你的暱稱、頭像、地區及性別',
success: res => {
console.log(res);
console.log(1);
},
fail: res => {
console.log(2);
console.log(res)
//拒絕授權
wx.showToast({
title: '您拒絕了請求,不能正常使用小程序',
icon: 'error',
duration: 2000
});
return;
}
});
} else if (res.cancel) {
//如果用戶點擊了取消按鈕
console.log(3);
wx.showToast({
title: '您拒絕了請求,不能正常使用小程序',
icon: 'error',
duration: 2000
});
return;
}
}
});
如果你還報錯,getUserProfile調用失敗:fail desc length does not meet the requirements,請看我另外一篇文章
微信小程序 getUserProfile直接進入fail函數,getUserProfile調用失敗:fail desc length does not meet the requirements
————————————————
版權聲明:本文爲CSDN博主「Gabriel_wei」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/Gabriel_wei/article/details/115607347