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

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

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

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章