my.getAuthCode

Call the API to obtain the authorization code (authCode). The authorization code can be used to obtain access token, so as to easily obtain the app user userId, nickname, etc.
For more information, please refer to the
user authorization

Sample Code

copy
my.getAuthCode({
  scopes: ['USER_ID','USER_NICKNAME','USER_AVATAR'],
  success: (res) => {
    my.alert({
      content: res.authCode,
    });
  },
  fail: (res) => {
      console.log(res.authErrorScopes)
  },
});

Parameters

Property

Type

Required

Description

scopes

Array

Yes

The scope of auth, there are 13 types:

USER_ID

,

USER_NICKNAME

,

USER_NAME

,

USER_LOGIN_ID

,

HASH_LOGIN_ID

,

USER_AVATAR

,

USER_GENDER

,

USER_BIRTHDAY

,

USER_NATIONALITY

,

USER_CONTACTINFO

,

USER_ADDRESS, SEND_MESSAGE,

auth_base

,

auth_user

.

success

Function

No

Callback function upon call success.

fail

Function

No

Callback function upon call failure.

complete

Function

No

Callback function upon call completion (to be executed upon either call success or failure).

Scopes Description

Scopes

Description

USER_ID

Authorized to obtain the unique user ID.

USER_NICKNAME

Authorized to obtain the user nickname.

USER_NAME

Authorized to obtain the user name.

USER_LOGIN_ID

Authorized to obtain the user login ID, which is several hidden bits of the phone number to protect users' privacy.

PLAINTEXT_USER_LOGIN_ID

Authorized to obtain the user login ID that without hidden bits.

HASH_LOGIN_ID

Authorized to obtain the hash user login ID.

USER_AVATAR

Authorized to obtain the user avatar.

USER_GENDER

Authorized to obtain the user gender.

USER_BIRTHDAY

Authorized to obtain the user birthday.

USER_NATIONALITY

Authorized to obtain the user nationality.

USER_CONTACTINFO

Authorized to obtain the user contact info.

USER_ADDRESS

Authorized to obtain the user address.

auth_base

Authorized to obtain the unique user ID.

auth_user

Authorized to obtain user information.

SEND_MESSAGE

Authorized to send notification to user via SMS/PUSH/INBOX.

USER_ID and auth_base are used to silently obtain user ID, silent authorization does not pop the frame and directly obtains user information. All the other scopes are used for proactive user authorization.

Note: The auth_base and auth_user are legacy scopes and not recommended to be used.

Callback Function

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

Property

Type

Required

Description

authCode

String

Y

Authorization code.

authErrorScopes

Key-value

Y

The scope that failed to grant authorization, key is the scope and value is the error.

authSuccessScopes

Array

Y

The scope that succeed to grant authorization.

Successful Response Example

copy
{
    "authCode":"1591797390204",
    "authSuccessScopes":['USER_ID', 'USER_NICKNAME', 'USER_AVATAR']
}

Failure Response Example

copy
{
    "authErrorScopes":{
       "USER_NICKNAME":"40006"
    }
}