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

hykeda2年前uniapp472

问题描述

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

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

————————————————

原文链接:https://blog.csdn.net/Gabriel_wei/article/details/115607347


相关文章

uni-app错误总结

H5页面中报错信息:[Vue warn]: Duplicate keys detected: 'pages/index/index'. This may cause an update...

uniapp开发微信小程序中使用block标签,在开发环境显示正常,生产环境中显示错误问题

在使用uniapp开发微信小程序时,使用了block标签进行了逻辑判断:<block v-show="list.type === 2">...

HBuilderX打开微信开发工具失败解决方案

先停止运行到微信开发工具, 然后在微信开发者工具设置-安全里面那个服务端口, 关闭再打开。重新运行就可以了 !...

关于uniapp中v-for循环使用slice(0, 4)导致click事件报错问题

关于uniapp中v-for循环使用slice(0, 4)导致click事件报错问题

在使用uniapp开发时遇到只要循环数组的前四个值,使用了slice函数,在添加click事件后报错:_vm.e0 is not a function<view   ...

uni-app注意点

uni-app注意点

vue只会将已经在data中声明的属性变为响应,没有声明的是不响应的,特别是数组和对象千万要注意export default({    data(){    &...

uniapp微信小程序保存base64图片的方法

使用uni.getFileSystemManager().writeFile去下载base64图片<view class="share-btn" @click="s...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。