my.getOpenUserInfo

Get the basic information about a user. This feature requires the user to deliberately trigger to activate the function. This function is not directly called by the API but rather waits for when the user has activated it by clicking a <button> component.

Use Attention

You need to set the value of the <button> component open-type to getAuthorize. After the user clicks and agrees, you can get the basic information returned by the Open Platform  through the my.getOpenUserInfo() interface.

Parameters

N/A

Success Callback Function

The incoming parameter is of the Object type with the following attributes:

NameTypeDescription
avatarStringUser avatar image url.
nickNameStringUser nickName.
genderStringUser gender. "m" is male,"f" is female
countryCodeStringThe  code of the country where  user is located, it should follow ISO 3166-1 alpha-2 code standard
provinceStringThe  province where  user is located
cityStringThe  city where  user is located

Sample Code

copy
<!-- .axml -->
<button 
    a:if="{{canIUseAuthButton}}" 
    open-type="getAuthorize" 
    onGetAuthorize="onGetAuthorize" 
    onError="onAuthError" 
    scope='userInfo'>
</button>

Button Property Description

NameDescription
open-typegetAuthorize(Must have this value).
scopeuserInfo(Must have this value).
onGetAuthorizeAuthorization success callback(We can call the interface for getting information in the callback)
onErrorAuthorization failure callback(Including user rejection and system exceptions)

Get User Basic Information

After the user clicks the consent, the user basic information can be obtained through my.getOpenUserInfo().

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

Return Res Message Format

  • An example of a successfully returned message format is as follows:

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

  • An example of a successfully returned message format is as follows:

{"response":"{"response":{"code":"40006","msg":"Insufficient Permissions","subCode":"isv.insufficient-isv-permissions","subMsg": "Insufficient permissions"}}"}