官方文档是这样写的,在bindagreeprivacyauthorization事件里面调用 wx.getUserProfile
但是在真机上却提示 getUserProfile:fail can only be invoked by user TAP gesture.
<view wx:if="{{showPrivacy}}">
<view>隐私弹窗内容....</view>
<button bindtap="handleOpenPrivacyContract">查看隐私协议</button>
<button id="agree-btn" open-type="agreePrivacyAuthorization" bindagreeprivacyauthorization="handleAgreePrivacyAuthorization">同意</button>
</view>
handleAgreePrivacyAuthorization() {
wx.getUserProfile({
desc: '用于完善信息',
success: (res) => {
},
fail: (e)=>{
console.log(e)
}
})
}
这个api已经废弃,并不会返回用户真实头像和昵称,你看官方隐私文档内的耦合方式调用。
<button id="agree-btn3" open-type="getUserInfo|agreePrivacyAuthorization" bindgetuserinfo="handleGetUserInfo" bindagreeprivacyauthorization="handleAgreePrivacyAuthorization">同意隐私协议并获取头像昵称信息</button> handleGetUserInfo(e) { // 获取头像昵称成功 console.log(e) }