title: Taro.authorize(option)
sidebar_label: authorize
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.
Type
(option: Option) => Promise<CallbackResult>
Parameters
Option
| Property | Type | Required | Description |
|---|---|---|---|
| scope | string |
Yes | The scope to be authorized. For details, see scope list |
| complete | (res: any) => void |
No | The callback function used when the API call completed (always executed whether the call succeeds or fails) |
| fail | (res: any) => void |
No | The callback function for a failed API call |
| success | (res: Result) => void |
No | The 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
| API | WeChat Mini-Program | H5 | React Native |
|---|---|---|---|
| Taro.authorize | ✔️ |
