Skip to main content
Version: Next

Taro.getUserProfile(option)

Gets information about the user. The authorization dialog pops up with each request and returns userInfo when the user agrees.

tip

WeChat Foundation Library 2.10.4 started to support

Taro 2.2.17,3.0.29,3.1,3.2 already supported.

WeChat adjustment background and instructions

getUserProfile

The user's personal information (avatar, nickname, gender and region) can be retrieved via the Taro.getUserProfile interface. This interface is supported by WeChat since version 2.10.4 of the base library and returns only the user's personal information, not the user identifier. The desc attribute of this interface (declaring what the user's personal information will be used for) will be displayed in a pop-up window later, so please fill in the form carefully.

Each time a developer obtains personal information from a user through this interface, user confirmation is required, so please keep the user's quickly filled in avatar nickname safe to avoid repeated pop-ups.

Type

(option?: Option) => Promise<SuccessCallbackResult>

Parameters

Option

PropertyTypeRequiredDescription
lang"en" | "zh_CN" | "zh_TW"NoThe language of the displayed user information
descstringYes声明获取用户个人信息后的用途,不超过 30 个字符
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

SuccessCallbackResult

PropertyTypeDescription
cloudIDstringThe Cloud ID corresponding to sensitive data. It is returned only in Mini Programs for which Cloud Base is enabled. The open data can be directly obtained via cloud call. See details.
encryptedDatastringThe complete encrypted user data, including the sensitive data. For details, see signature, verification, encryption, and decryption of user data.
ivstringThe initial vector of the encryption algorithm. For details, see signature, verification, encryption, and decryption of user data.
rawDatastringRaw data string that excludes sensitive information and is used to calculate signatures.
signaturestringThe string generated with SHA-1 (rawData + sessionkey), which is used to verify the user information. For details, see signature, verification, encryption, and decryption of user data.
userInfo UserInfo User information object, excluding openid and other sensitive information.

Sample Code

Taro.getUserProfile({
desc: 'For completing member profiles',
success: (res) => {
this.setState({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})

API Support

APIWeChat Mini-ProgramH5React Native
Taro.getUserProfile✔️

Other

issue : Taro什么时候支持 getUserProfile 方法