The applet fails to obtain user information using getUserInfo

1. Use getUserInfo

 wx.getUserInfo({
    
    
      success: (res) => {
    
    
        console.log(res);
        this.setData({
    
    
          userInfo: res.userInfo
        })
      },
      fail: (err) => {
    
    
        console.log(err);
      }
    })
  },

The obtained information:
insert image description here
that is, the user's avatar and nickname cannot be obtained

2. Reason

The new version of WeChat development tools recommends using wx.getUserProfile to obtain user information

getUserProfile(e) {
    
    
    // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
    wx.getUserProfile({
    
    
      desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
      success: (res) => {
    
    
        console.log(res)
        this.setData({
    
    
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    })
  },

3. What if you have to use getUserInfo?

Answer: yes

The method is to replace the project.config.json version with the old version. The old version can use getUserInfo to get user information. Of course, the official recommendation is to use new ones, so let's use new ones to save trouble.

(old version below)

{
    
    
    "description": "项目配置文件",
    "packOptions": {
    
    
        "ignore": []
    },
    "setting": {
    
    
        "urlCheck": true,
        "es6": true,
        "enhance": true,
        "postcss": true,
        "preloadBackgroundData": false,
        "minified": true,
        "newFeature": true,
        "coverView": true,
        "nodeModules": false,
        "autoAudits": false,
        "showShadowRootInWxmlPanel": true,
        "scopeDataCheck": false,
        "uglifyFileName": false,
        "checkInvalidKey": true,
        "checkSiteMap": true,
        "uploadWithSourceMap": true,
        "compileHotReLoad": false,
        "lazyloadPlaceholderEnable": false,
        "useMultiFrameRuntime": true,
        "useApiHook": true,
        "useApiHostProcess": true,
        "babelSetting": {
    
    
            "ignore": [],
            "disablePlugins": [],
            "outputPath": ""
        },
        "useIsolateContext": true,
        "userConfirmedBundleSwitch": false,
        "packNpmManually": false,
        "packNpmRelationList": [],
        "minifyWXSS": true,
        "disableUseStrict": false,
        "minifyWXML": true,
        "showES6CompileOption": false,
        "useCompilerPlugins": false,
        "ignoreUploadUnusedFiles": true
    },
    "compileType": "miniprogram",
    "libVersion": "2.13.1",
    "appid": "wx7a5dfd35d20f6982",
    "projectname": "wechat_study",
    "debugOptions": {
    
    
        "hidedInDevtools": []
    },
    "isGameTourist": false,
    "simulatorType": "wechat",
    "simulatorPluginLibVersion": {
    
    },
    "condition": {
    
    
        "search": {
    
    
            "list": []
        },
        "conversation": {
    
    
            "list": []
        },
        "game": {
    
    
            "currentL": -1,
            "list": []
        },
        "miniprogram": {
    
    
            "list": []
        }
    }
}

The effect of obtaining user information in the old version is as follows:
insert image description here

Guess you like

Origin blog.csdn.net/CathyleeQ/article/details/124371062
Recommended