Taro.getUserProfile(option)
Gets information about the user. The authorization dialog pops up with each request and returns userInfo
when the user agrees.
WeChat Foundation Library 2.10.4 started to support
Taro 2.2.17,3.0.29,3.1,3.2 already supported.
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
Property | Type | Required | Description |
---|---|---|---|
lang | "en" | "zh_CN" | "zh_TW" | No | The language of the displayed user information |
desc | string | Yes | 声明获取用户个人信息后的用途,不超过 30 个字符 |
complete | (res: any) => void | No | The callback function used when the API call completed (always executed whether the call succeeds or fails) |
fail | (res: any) => void | No | The callback function for a failed API call |
success | (res: Result) => void | No | The callback function for a successful API call |
SuccessCallbackResult
Property | Type | Description |
---|---|---|
cloudID | string | The 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. |
encryptedData | string | The complete encrypted user data, including the sensitive data. For details, see signature, verification, encryption, and decryption of user data. |
iv | string | The initial vector of the encryption algorithm. For details, see signature, verification, encryption, and decryption of user data. |
rawData | string | Raw data string that excludes sensitive information and is used to calculate signatures. |
signature | string | The 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
API | WeChat Mini-Program | H5 | React Native |
---|---|---|---|
Taro.getUserProfile | ✔️ |
Other
issue : Taro什么时候支持 getUserProfile 方法