irpas技术客

微信小程序 getUserProfile直接进入fail函数,getUserProfile调用失败:fail can only be invoked by us

未知 2123

问题描述

小程序更改了调用用户信息的接口,详情

调用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


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #微信小程序 #can #only #be #invoked #by