收藏
回答

小程序运行在PC端桌面上,wx.getUserProfile接口不支持,无法实现微信授权登录

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug wx.getUserProfile 微信iOS客户端 3.2.1 2.16

在PC桌面上运行小程序,wx.getUserProfile不支持,导致无法实现授权登录,请问PC端何时支持此接口?或者此问题该如何解决?谢谢



回答关注问题邀请回答
收藏

2 个回答

  • 安逸
    安逸
    2021-05-27

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

    底部有例子,适配一下就行了。

    2021-05-27
    有用 1
    回复 1
    • Andy
      Andy
      2021-05-27
      怎么适配?只能是不报错,或者使用getUserInfo,但是拿不到昵称和头像,与getUserProfile的效果不同啊
      2021-05-27
      回复
  • Ta👿 斗
    Ta👿 斗
    2021-06-23

    就在获取用户授权得时候直接try catch一下就好了。走不了新的wx.getUserProfile就走老的wx.getUserInfo

    let that = this 
    try{
            //  新版
            wx.getUserProfile({
                desc: '用于完善会员资料',
                success: (res) => {
                    let {avatarUrl, gender, nickName,province,city}=res.userInfo
                    that.setData({ avatarUrl, gender, nickName })
                    wx.login({
                        success: (rest) => {
                            if (rest.code) {
                                that.getOpenId(rest.code,that)
                            } else {
                                wx.showToast({
                                    title: '授权失败',
                                    icon: 'none',
                                    duration: 3000
                                });
                            }
                        }
                    });
                },
                fail(e){
                    console.log(e)
                }
            })
        }catch(e){
            //  老版
            //进入未授权 -- wx.getUserInfo获取用户信息 
            wx.getUserInfo({
                success: function(ress) {
                    let {avatarUrl, gender, nickName,province,city}=ress.userInfo
                    that.setData({ avatarUrl, gender, nickName })
                    wx.login({
                        success: (rest) => {
                            if (rest.code) {
                                that.getOpenId(rest.code,that)
                            } else {
                                wx.showToast({
                                    title: '授权失败',
                                    icon: 'none',
                                    duration: 3000
                                });
                            }
                        }
                    });
                }
            })
        }
    


    2021-06-23
    有用
    回复
登录 后发表内容