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: ['User_Base_Info'],
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, including:
|
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_Base_Info | Authorized to silently obtain user ID only. |
User_Customer_Info | Authorized to obtain user ID, phone number, email address, and delivery address list |
User_Customer_KYC_Info | Authorized to obtain user ID, phone number, email address, delivery address list, document type, document no, name and surname(last name) |
Note: User_Base_Info 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. key is the scope and value is the error. |
authSuccessScopes | Array | Yes | The scope that succeeds to grant authorization. |
Successful response example
{
"authCode":"1591797390204",
"authSuccessScopes":['User_Base_Info']
}
Failure response example
{
"authErrorScopes":{
"User_Base_Info":"10001"
}
}