ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2022-07-02 10:02:21  阅读:245  来源: 互联网

标签:调用 TAP log res fail console getUserProfile


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

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

 

标签:调用,TAP,log,res,fail,console,getUserProfile
来源: https://www.cnblogs.com/mr-hu2009/p/16436735.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有