100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 微信小程序4月13号新更新getUserInfo要用wx.getUserProfile接口替换

微信小程序4月13号新更新getUserInfo要用wx.getUserProfile接口替换

时间:2022-02-22 19:51:07

相关推荐

微信小程序4月13号新更新getUserInfo要用wx.getUserProfile接口替换

4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息,所以请尽快更新微信小程序授权登录接口。

wx.getUserProfile(Object object)

获取用户信息。每次请求都会弹出授权窗口,用户同意后返回userInfo

参数

Object object

object.lang 的合法值

object.success 回调函数

参数

Object res

示例代码

<view class="container"><view class="userinfo"><block wx:if="{{!hasUserInfo}}"><button wx:if="{{canIUseGetUserProfile}}" bindtap="getUserProfile"> 获取头像昵称 </button><button wx:else open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button></block><block wx:else><image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image><text class="userinfo-nickname">{{userInfo.nickName}}</text></block></view></view>

Page({data: {userInfo: {},hasUserInfo: false,canIUseGetUserProfile: false,},onLoad() {if (wx.getUserProfile) {this.setData({canIUseGetUserProfile: true})}},getUserProfile(e) {// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认// 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗wx.getUserProfile({desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写success: (res) => {this.setData({userInfo: res.userInfo,hasUserInfo: true})}})},getUserInfo(e) {// 不推荐使用getUserInfo获取用户信息,预计自4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息this.setData({userInfo: e.detail.userInfo,hasUserInfo: true})},})

来源:

https://developers./miniprogram/dev/api/open-api/user-info/wx.getUserProfile.html

备注:

今天有朋友问我,为什么更新了接口,编辑器本地调试不出来呢。PC调试时,显示的基础库版本是2.11.0,不是说的2.10.4就支持吗?

建议大家把编辑器升级到最新就问题了。旧版的不支持wx.getUserProfile这个方法,真机上是没有问题的。看我的调试基础库已经升级到最新2.16.1

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。