Obtain basic user information

The Mini Program is allowed to obtain basic information of the wallet users. This is an open service which, after a user's authorization, captures basic user information such as avatar, nickname, gender, and region.

Requirements

When obtaining basic user information, mini program developers must meet the following requirements:

  • Do not guide users to grant authorization at the launch of the mini program. Users have the right to fully understand the mini program and its operations before giving any authorization.
  • Do not obtain the user ID and the user's real name. The information to obtain can only include basic user information, such as user avatar, nickname, gender, and location.
  • As the basic user information and the user's mobile phone number are obtained by two JSAPIs, these two kinds of information cannot be requested in the same modal.
  • Do not obtain user information that is not related with the business. If the user does not grant authorization on the first request, display the modal to allow the user to reverse the decision when the business requires the authorization again.

Procedures

To obtain the user's basic information in the mini program, mini program developers must complete the following steps:

Step 1: Create a mini program

Apply for an account and create a mini program on the Mini Program platform.

Step 2: Add the feature

In the created mini program, add the feature of obtaining basic user information under the Features tab.

Obtain basic user information

Step 3: Call the JSAPI

Call the my.getOpenUserInfo JSAPI to obtain the user's basic information.

Note:

Developers must consider the possibility of users rejecting to grant the mini program authorization to collect their user information. For such cases, developers must have corresponding solutions, such as guiding the user to manually fill in or upload the user information.

Display the authorization modal

In the button component, set the value of open-type as getAuthorize and set the value of scope as userInfo.

Sample code:

copy
<!-- .axml -->
<button 
    open-type="getAuthorize" 
    onGetAuthorize="onGetAuthorize" 
    onError="onAuthError" 
    scope='userInfo'>
</button>

Button properties

NameDescription
open-type

The value is getAuthorize.

scope

The value is userInfo.

onGetAuthorizeAuthorization success callback. The Mini Program can call my.getOpenUserInfo to get information in this callback.
onError Authorization failure callback, including user rejection and system exceptions.

Call the my.getOpenUserInfo JSAPI

After the user grants the authorization, the user basic information can be obtained by calling the my.getOpenUserInfo JSAPI.

Sample code:

copy
// .js 
onGetAuthorize(res) {
    my.getOpenUserInfo({
        fail: (res) => {
        },
        success: (res) => {
            let userInfo = JSON.parse(res.response).response
        }
    });
}

Sample of a successfully returned message format:

copy
{
    "response":{
        "response":{
            "code":"10000",
            "msg":"Success",
            "countryCode":"code",
            "gender":"f",
            "nickName":"XXX",
            "avatar":"https://image_domain/images/partner/XXXXXXXX",
            "city":"city",
            "province":"province"
        }
    }
}

FAQs

Can the function of obtaining basic user information obtain the wallet userId?

No. If mini programs need to obtain the user ID, see user authorization for details and call my.getAuthCode to get the user ID.

Can the mini program obtain the user's public information such as mobile phone number, avatar, and nickname at the same time?

Mini programs cannot obtain user's mobile phone number, avatar, nickname at the same time in the same modal.

The following public user information can be obtained with my.getOpenUserInfo:

  • Avatar
  • Nickname
  • Gender
  • Country

The following private user information can be obtained with my.getAuthCode:

  • User ID
  • Phone number

Can mini programs get user ID, real name and private user information through the function of obtaining basic user information?

No. Through the function of obtaining basic user information, mini programs can only get user avatar, nickname, gender, location, and other public information.