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, refer to the
user authorization.

Sample code

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

Parameters

Property

Type

Required

Description

scopes

String/Array

Yes

The scope of authorization, including:

  • auth_base
  • auth_user

(auth_base is silent authorization)

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

auth_base

Authorized to obtain the unique user ID.

auth_user

Authorized to obtain user information.

Note:

  • 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.
  • 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

Yes

Authorization code.

authErrorScopes

Key-value

Yes

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

authSuccessScopes

Array

Yes

The scope that succeed to grant authorization.

Successful response example

copy
{
    "authCode":"1591797390204",
    "authSuccessScopes":['auth_user']
}

Failure response example

copy
{
    "authErrorScopes":{
       "auth_user":"40006"
    }
}