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. |
USER_NICKNAME | proactive, authorized to obtain user nickname only。 |
USER_NAME | proactive, authorized to obtain user name only。 |
USER_LOGIN_ID | proactive, authorized to obtain user login ID only。 |
USER_GENDER | proactive, authorized to obtain user gender only。 |
USER_BIRTHDAY | proactive, authorized to obtain user birthday only。 |
USER_NATIONALITY | proactive, authorized to obtain user nationality only。 |
USER_EMAIL | proactive, authorized to obtain user email only。 |
USER_ADDRESS | proactive, authorized to obtain user address only。 |
USER_MOBILE_PHO NE | proactive, authorized to obtain user mobile phone only。 |
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 | No | Authorization code. |
authErrorScopes | Key-value | No | The scope that fails to grant authorization. |
authSuccessScopes | Array | No | The scope that succeeds to grant authorization. |
error | Int | No | Error code |
errorMessage | String | No | Error Message |
Error codes
error | errorMessage | |
3 | ERROR_UNKNOW | Unknown error! |
10 | ERROR_CODE_EMPTY | Empty authCode |
11 | USER_CANCEL | Unauthorized to get user info |
1000 | ERROR_CODE_UNKNOWN_ERROR | Unknown error |
1001 | ERROR_CODE_USER_CANCEL | The user cancels the operation. |
1005 | ERROR_CODE_SYSTEM_ERROR | System error |
JSAPI Error response example
{
"error":3,
"errorMessage":"Unknown error!"
}
Successful response example
{
"authCode":"1591797390204",
"authSuccessScopes":['auth_base']
}
Failure response example
{
"authErrorScopes":{
"auth_user":"10001"
}
}