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

copy
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, including:

  • auth_base
  • auth_user
  • SEND_MESSAGE

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 silently obtain the user ID only.

auth_user

Authorized to obtain user information.

SEND_MESSAGE

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

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. key is the scope and value is the error.

authSuccessScopes

Array

Yes

The scope that succeeds to grant authorization.

Successful response example

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

Failure response example

copy
{
    "authErrorScopes":{
       "auth_user":"10001"
    }
}