# Getting User Information

User information includes the alias, profile photo, gender, and other personal information of Weixin users.

# Getting Information the First Time

User's personal information is sensitive. Therefore, the user must grant authorization before you can get user information. For more information, see Authorization. You can use wx.creawteUserInfoButton to instruct the user to grant authorization.

const button = wx.createUserInfoButton({
  type: 'text',
  text: 'Get user information',
  style: {
    left: 10,
    top: 76,
    width: 200,
    height: 40,
    lineHeight: 40,
    backgroundColor: '#ff0000',
    color: '#ffffff',
    textAlign: 'center',
    fontSize: 16,
    borderRadius: 4
  }
})
button.onTap((res) => {
  // User information can be obtained here
})

# Getting Information with Authorization

If the user has authorized the Mini Game to get personal information, the developer can record the user's personal information in the console. However, users may change their aliases and profile photos. So, to ensure the personal information remains valid, you must get user information again. At this time, instead of using wx.createUserInfoButton, you can simply call wx.getUserInfo to directly get the user information.

wx.getUserInfo({
  success(res) {
    // User information can be obtained here
  }
})

# Getting Information in Open Data Domain

If the user information obtained is only displayed and not stored in the console, you can get the information via the open data domain API OpenDataContext-wx.getUserInfo. Because this API is immune to data leaks, you can call it without getting the user's authorization.