Skip to main content
Version: Next

Taro.authorize(option)

Initiates an authorization request to the user in advance. After this API is called, a pop-up box appears to ask whether the user agrees to authorize the Mini Program to use a specific feature or obtain certain data of the user, but the appropriate APIs are not actually called. If the user has already given the authorization, the pop-up box will not appear, and a message indicating success is returned directly. For more usages, see User Authorization.

Reference

Type

(option: Option) => Promise<CallbackResult>

Parameters

Option

PropertyTypeRequiredDescription
scopestringYesThe scope to be authorized. For details, see scope list
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

Sample Code

// Use Taro.getSetting to query whether the user has authorized the "scope.record".
Taro.getSetting({
success: function (res) {
if (!res.authSetting['scope.record']) {
Taro.authorize({
scope: 'scope.record',
success: function () {
// The user has allowed the Mini Program to use the recording feature. When the Taro.startRecord API is called later, the pop-up box will not appear.
Taro.startRecord()
}
})
}
}
})

API Support

APIWeChat Mini-ProgramH5React Native
Taro.authorize✔️