my.getAuthCode
Call the API to obtain the authorization code. The authorization code can be used to obtain the access token, so as to obtain the app user's information, such as user ID and nickname.
For more information, refer to User authorization.
Sample code
my.getAuthCode({
scopes: ['auth_base'],
success: (res) => {
my.alert({
content: res.authCode,
});
},
fail: (res) => {
console.log(res.authErrorScopes)
},
});
Parameters
Property | Type | Required | Description |
scopes | Array | Yes | The scope of authorization. For more information about its valid values, refer to Scope description. |
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
Valid value | Description |
auth_base | Authorized to silently obtain user ID only. |
auth_user | Authorized to obtain user ID and other user information. |
SEND_MESSAGE | Authorized to send notifications to the user via SMS, PUSH, or INBOX. |
USER_NICKNAME | Authorized to obtain the user nickname. |
USER_NAME | Authorized to obtain the user name. |
USER_LOGIN_ID | Authorized to obtain the user's login ID. |
PLAINTEXT_USER_LOGIN_ID | Authorized to obtain the user's plaintext login ID. |
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's gender. |
USER_BIRTHDAY | Authorized to obtain the user's birthday. |
USER_NATIONALITY | Authorized to obtain the user's nationality. |
USER_CONTACTINFO | Authorized to obtain the user's contact information. |
USER_ADDRESS | Authorized to obtain the user's address. |
PLAINTEXT_MOBILE_PHONE | Authorized to obtain the user's plaintext phone number. |
Note:
auth_base
is used to silently obtain user ID only. Silent authorization does not pop the frame and directly obtains user information. All the other scopes are used for proactive user authorization.
Callback function
The incoming parameter is of the Object type with the following attributes:
Property | Type | Required | Description |
authCode | String | Yes | Authorization code. |
authErrorScopes | Key-value | Yes | The scope that fails to grant authorization. |
authSuccessScopes | Array | Yes | The scope that succeeds to grant authorization. |
Successful response example
{
"authCode":"1591797390204",
"authSuccessScopes":['auth_base']
}
Failure response example
{
"authErrorScopes":{
"auth_user":"10001"
}
}